zoukankan      html  css  js  c++  java
  • 题解 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
  • 相关阅读:
    (JS/JQ)与Ajax
    JS与JQ的DOM处理
    正则表达式
    JS事件大全
    CSS(初级)学习笔记
    HTML学习笔记
    leetcode记录——65. 有效数字
    dp专题
    Hackerrank---A stones game
    组合博弈问题
  • 原文地址:https://www.cnblogs.com/zdsrs060330/p/13095033.html
Copyright © 2011-2022 走看看