UVa 10465 - Homer Simpson
2012-04-04 11:14
169 查看
乍一看是道线性规划题,不由想去找数学解法;
其实还是个完全背包,只不过只有两件物品,体积就是所耗时间,重量为1;
需要注意题目的描述:
For each test case, print in a single line the maximum number of burgers Homer can eat without having beer. If homer must have beer, then also print the time he gets for drinking, separated by a single space. It is preferable that Homer drinks as little beer as possible.
1A万岁!
数学解法可能与数论有关,尚未考虑。
其实还是个完全背包,只不过只有两件物品,体积就是所耗时间,重量为1;
需要注意题目的描述:
For each test case, print in a single line the maximum number of burgers Homer can eat without having beer. If homer must have beer, then also print the time he gets for drinking, separated by a single space. It is preferable that Homer drinks as little beer as possible.
1A万岁!
# include <stdio.h> # include <memory.h> # define MAX(x,y) ((x)>(y) ? (x):(y)) # define INF (1<<30) int c[2]; int f[10001]; int main() { int t, i, v; while (~scanf("%d%d%d", &c[0], &c[1], &t)) { f[0] = 0; for (i = 1; i <= 10000; ++i) f[i] = -INF; for ( i = 0; i <= 1; ++i) for ( v = c[i]; v <= t; ++v) f[v] = MAX(f[v], f[v-c[i]]+1); v = t; while ( f[v] < 0) --v; printf("%d", f[v]); if (v != t) printf(" %d", t-v); putchar('\n'); } return 0; }
数学解法可能与数论有关,尚未考虑。
相关文章推荐
- 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 HomerSimpson
- UVA - 10465 Homer Simpson
- UVA 10465 Homer Simpson
- UVa 10465 - Homer Simpson DP 完全背包
- Uva 10465 — Homer Simpson
- 10465 - Homer Simpson
- 10465 - Homer Simpson
- uva 10465 (Homer Simpson) (DP)
- UVa 10465 Homer Simpson
- UVa 10465 - Homer Simpson 背包
- UVA 10465 - Homer Simpson
- UVA - 10465 Homer Simpson
- UVa 10465 - Homer Simpson