hdu2159 Fate 二维背包

简介:

#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define ll __int64
using namespace std;

int n,v,k,s,dp[110][110],w[110],c[110];

int main()
{
    int i,j,p;
    while(~scanf("%d%d%d%d",&n,&v,&k,&s))
    {
        for(i=1;i<=k;i++)
            scanf("%d%d",&w[i],&c[i]);

        memset(dp,0,sizeof dp);
        for(i=1;i<=v;i++)//背包容量
        {
            for(j=1;j<=k;j++)//几种物品
            {
                for(p=1;p<=s;p++)//选几样
                {
                    if(i>=c[j])
                        dp[i][p]=max(dp[i][p],dp[i-c[j]][p-1]+w[j]);
                }
            }
        }

        if(dp[v][s]<n) printf("-1\n");
        else
        {
            for(i=v-1;i>=0;i--)
            {
               // printf("i:%d dpis:%d\n",i,dp[i][s]);
                if(dp[i][s]<n)
                {
                    printf("%d\n",v-i-1);
                    break;
                }
            }
        }
    }
    return 0;
}








本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5124330.html,如需转载请自行联系原作者
相关文章
|
机器学习/深度学习 Java
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
UVA10474 大理石在哪儿 Where is the Marble?
UVA10474 大理石在哪儿 Where is the Marble?
2019CCPC秦皇岛HDU - 6736 F - Forest Program(dfs找环 组合数学)
2019CCPC秦皇岛HDU - 6736 F - Forest Program(dfs找环 组合数学)
98 0
HDU 3506 Monkey Party(动态规划)
HDU 3506 Monkey Party(动态规划)
59 0
HDU 3506 Monkey Party(动态规划)
POJ-2488,A Knight's Journey(DFS)
POJ-2488,A Knight's Journey(DFS)
HDU-1846,Brave Game(巴什博弈)
HDU-1846,Brave Game(巴什博弈)
|
机器学习/深度学习 自然语言处理
UVA - 10474 Where is the Marble
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them.
1418 0
|
Java
2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1060    Accepted Submission(...
1208 0