uva_10465 Homer Simpson
2012-11-05 19:06
337 查看
简单的完全背包问题 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAXV 10001 int dp[MAXV]; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif int n, m, t; while( ~scanf("%d %d %d", &n, &m, &t) ) { memset(dp, 0, sizeof(dp)); dp[0] = 1; for(int v = 0; v <= t-n; v ++) { if( dp[v] ) { dp[v+n] = max(dp[v+n], dp[v]+1); } } for(int v = 0; v <= t-m; v ++) { if( dp[v] ) { dp[v+m] = max(dp[v+m], dp[v]+1); } } if( dp[t] ) { printf("%d\n", dp[t]-1); continue; } for(int v = t; v >= 0; v --) { if( dp[v] ) { printf("%d %d\n", dp[v]-1, t-v); break; } } } return 0; }
相关文章推荐
- uva 10465 - Homer Simpson
- uva10465 - Homer Simpson(完全背包)
- UVA 10465 - Homer Simpson 贪心
- uva 10465 Homer Simpson(完全背包)
- uva 10465 - Homer Simpson
- UVA 10465 Homer Simpson(完全背包: 二维目标条件)
- uva 10465 Homer Simpson(完全背包)
- UVa 10465 - Homer Simpson
- Uva-10465-Homer Simpson
- UVA 10465 - Homer Simpson 贪心或完全背包
- UVa 10465 - Homer Simpson 背包
- uva 10465 Homer Simpson
- UVa 10465 - Homer Simpson 背包
- uva 10465 - Homer Simpson(贪心)
- uva 10465 (Homer Simpson) (DP)
- UVA 10465 Homer Simpson(dp + 完全背包)
- UVA 10465 - Homer Simpson
- UVa 10465 Homer Simpson
- UVa 10465 - Homer Simpson
- uva 10465 - Homer Simpson(贪心+完全背包)