寒冰王座 hdu 1248(背包)

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#define maxn 11000
using namespace std;
int dp[maxn];

int main()
{
    int T, n;

    scanf("%d", &T);

    int a[3]={150, 200, 350};

    while(T --)
    {
        scanf("%d", &n);

        memset(dp, 0, sizeof(dp));

        for(int i=0; i<3; i++)
        {
            for(int j=a[i]; j<=n; j++)
            {
                dp[j]=max(dp[j], dp[j-a[i]]+a[i]);
            }
        }

        printf("%d
", n-dp[n]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/daydayupacm/p/5914223.html