Frozen Throne (HDU 1248) (full backpack)

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

Template backpack full of questions

Code:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <list>
#include <map>
#define P(x) x>0?x:0
#define INF 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef vector<int>:: iterator VITer;
const int maxN=1e4+5;//最大货币面值

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

int N;
int dp[maxN];//能花的最多的钱
int ans;
int v[maxN];

void init()
{
    memset(dp,0, sizeof(dp));
    ans=0;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        init();
        scanf("%d",&N);
        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]);
            }
        }
        for(int i=1;i<=N;i++)
        {
            ans=max(ans,dp[i]);
        }
        printf("%d\n",N-ans);
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44049850/article/details/94717830