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

来源:互联网 发布:佛教的本质是骗局 知乎 编辑:程序博客网 时间:2024/05/29 19:25

完全背包裸题,不多说了~直接上代码。

#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <set>#include <map>#include <queue>#include <stack>#include <assert.h>#include <malloc.h>typedef long long LL;#define INF 500000001using namespace std;int dp[100001];int main(){    //freopen("test0.in", "r", stdin);    //freopen("test0.out", "w", stdout);    int n, m, a[101], b[101];    while(~scanf("%d", &n))    {        for(int i = 0; i < n; i++)        {            scanf("%d %d", &a[i], &b[i]);        }        scanf("%d", &m);        memset(dp, 0, sizeof(dp));        for(int i = 0; i < n; i++)        {            for(int V = b[i]; V <= m; V++)            {                dp[V] = max(dp[V], dp[V-b[i]]+a[i]);            }        }        printf("%d\n", dp[m]);    }    return 0;}


0 0
原创粉丝点击