苹果

2017-11-22 08:38:20来源:CSDN作者:Duke10人点击

分享

这里写图片描述

#include<stdio.h>#include<string.h>#define MAX(a,b) (a > b ? a : b)int main(){    int n, v;    while (~scanf("%d%d",&n, &v) && n + v != 0)    {        int i, j, volume, value, dp[v+1];        memset(dp, 0, sizeof(dp));        for (i = 1; i <= n; i++)        {            scanf("%d%d",&volume, &value);            for (j = v; j >= volume; j--)                dp[j] = MAX(dp[j], dp[j-volume] + value);        }        printf("%d/n",dp[v]);    }    return 0;}/*int main(){    int n, v;    while (~scanf("%d%d",&n, &v) && n + v != 0)    {        int i, j, volume[n+1], value[n+1];        memset(volume, 0, sizeof(volume));        memset(value, 0, sizeof(value));        for (i = 1; i <= n; i++)            scanf("%d%d",&volume[i], &value[i]);        int dp[n+1][v+1];        memset(dp, 0, sizeof(dp));        for (i = 1; i <= n; i++)        {            for (j = 1; j <= v; j++)            {                if (volume[i] > j)                    dp[i][j] = dp[i-1][j];                else                    dp[i][j] = MAX(dp[i-1][j], dp[i-1][j-volume[i]]+value[i]);            }        }        printf("%d/n",dp[n][v]);    }    return 0;}*/

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台