[UVA]10465 - Homer Simpson(完全背包问题)

来源:互联网 发布:奇兵网络怎么刷金 编辑:程序博客网 时间:2024/04/29 08:33

完全背包问题。

#include <iostream>#include <cstdlib>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <set>#include <map>#include <stack>#include <algorithm>using namespace std;const int maxd = 100000 + 10;const int  INF = 1 << 20;int t;int main(){    int v[2];    while(scanf("%d%d%d",&v[0],&v[1],&t) != EOF){        int dp[maxd];        for(int i = 0 ; i <= t ; i ++) dp[i] = - INF;        dp[0] = 0;        for(int i = 0 ; i < 2 ; i++)            for(int j = 0 ; j <= t ; j ++)                if(j - v[i] >= 0){                    dp[j] = max(dp[j],dp[j - v[i]] + 1);                }        for(int i = t ; i >= 0 ; i --){            if(dp[i] >= 0){                if(i == t)                    printf("%d\n",dp[i]);                else                    printf("%d %d\n",dp[i],t - i);                break;            }        }    }    return 0;}

0 0