UVa 11450 Wedding shopping (DP)
2014-02-25 16:28
387 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2445
采用滚动数组实现。
此外,这题颇有点模拟的味道。
完整代码:
采用滚动数组实现。
此外,这题颇有点模拟的味道。
完整代码:
/*0.035s*/ #include<bits/stdc++.h> using namespace std; bool dp[205]; vector<int> tmp;///临时数组 int main() { int t, m, c, k, cost, i, mx, tmpmx; bool finalok, ok; scanf("%d", &t); while (t--) { scanf("%d%d", &m, &c); memset(dp, 0, sizeof(dp)); finalok = dp[tmpmx = 0] = true; while (c--) { scanf("%d", &k); ok = false; tmp.clear(); while (k--) { scanf("%d", &cost); if (finalok) for (i = 0; i <= mx && i + cost <= m; ++i) if (dp[i]) ok = true, tmpmx = max(tmpmx, i + cost), tmp.push_back(i + cost); } mx = tmpmx; memset(dp, 0, sizeof(dp)); for (i = 0; i < tmp.size(); ++i) dp[tmp[i]] = true; if (finalok) finalok = ok; } if (finalok) printf("%d\n", mx); else puts("no solution"); } return 0; }
相关文章推荐
- AOP事物处理中的传播行为详解
- linux下opencv安装和配置
- 在Eclipse中运行Tomcat6源代码,保证正确的classpath
- POJ-1521/ZOJ-1117/Entropy
- CentOS系统主机名与IP地址、网关、DNS服务的配置
- linux点滴
- hadoop使用lzo压缩文件笔记 (cdh3u0)
- linux和windows下mysql密码怎样清空!
- windows server 2008 下安装openmeetings 2.2.0
- 针对nginx、haproxy、lvs 的优缺点分析
- 针对nginx、haproxy、lvs 的优缺点分析
- Wo Cloud CentOS 挂载磁盘小计
- hadoop 2.2.0 集群部署 坑
- Linux socket编程
- linux ------ Platform设备驱动
- 基于AOP实现权限管理:通过shiro认证身份和模拟授权认证
- [Binospace] Linux系统性能分析的实践方法
- 4 reasons developers are scared of making their code public
- linux命令学习笔记
- linux命令学习笔记