莫名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;
 } 

相关文章:

  • 2021-09-25
  • 2021-08-25
  • 2022-02-09
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-30
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
相关资源
相似解决方案