您的位置:首页 > 其它

HDU 4508 湫湫系列故事——减肥记I

2014-11-09 13:40 197 查看

http://acm.hdu.edu.cn/showproblem.php?pid=4508

简单完全背包

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

const int N=100010;

using namespace std;
struct job{
    int value,w;
}node
;

int n,m,dp
;
int main(){
//    freopen("in.txt", "r", stdin);
    while(scanf("%d",&n) == 1){
        for(int i=1; i<=n; i++)
            scanf("%d%d",&node[i].value,&node[i].w);
        scanf("%d",&m);
        memset(dp, 0, sizeof(dp));
        for(int i=1; i<=n; i++){
            for(int j=node[i].w; j<=m; j++){
                dp[j] = max(dp[j], dp[j-node[i].w] + node[i].value);
            }
        }
        printf("%d\n",dp[m]);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: