题解 CF294B 【Shaass and Bookshelf】

莫名a了,发一波题解

#include<bits/stdc++.h>//万能头文件
using namespace std;


int dp[105];//数组不必开大,哈哈哈
struct pos
{
	int t;
	int w;
}a[105];//哦,我可爱的结构体
 
 
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].t>>a[i].w;
		sum+=a[i].t;//算和
	}//读入
	for(int i=1;i<=sum;i++)
		dp[i]=1000000009;//初始化
		
		
	for(int i=0;i<n;i++)
		for(int j=sum;j>=a[i].t;j--)
			dp[j]=min(dp[j],dp[j-a[i].t]+a[i].w);//01背包
			
			
	int k;
	for(int i=sum;i>=0;i--)
	{
		if(sum-i>=dp[i])
		{
			k=sum-i;
			break;
		}
	}//题目说“The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books.”
	
	
	cout<<k<<endl;//输出啦,啦啦啦
	return 0;
 } 
qaqaq
原文地址:https://www.cnblogs.com/zdsrs060330/p/13095033.html