7

CF GYM 10499J Healthy Recipes(DP)

 3 years ago
source link: https://arminli.com/cf-gym-10499j/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Armin's Blog

CF GYM 10499J Healthy Recipes(DP)

December 03, 2015

题目链接

题意观察样例与提示即可。

挺水的 DP 题,DP 刷的比较少。。

#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
long long a[105], dp[10005];

int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        memset(dp, 0, sizeof(dp));
        int n, m, k;
        dp[0] =1;
        scanf("%d %d %d", &n, &m, &k);
        for(int i = 1; i <= n; i++){
            scanf("%I64d", &a[i]);
        }
        for(int i = 1; i <= n; i++){
            for(int j = m; j >= a[i]; j--){
                dp[j] += dp[j-a[i]];
            }
            if(dp[m] >= k)
                break;
        }
        if(dp[m] >= k) cout << "ENOUGH" << endl;
        else cout << dp[m] << endl;
    }
    return 0;
}

Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK