hihoCoder 1043 : 完全背包
来源:互联网 发布:大数据安全需求分析 编辑:程序博客网 时间:2024/06/05 22:36
题意:见原题。
思路:
空间优化:
AC代码
#include <cstdio>#include <cmath>#include <cctype>#include <bitset>#include <algorithm>#include <cstring>#include <utility>#include <string>#include <iostream>#include <map>#include <set>#include <vector>#include <queue>#include <stack>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10#define inf 0x3f3f3f3f#define PI pair<int, int> typedef long long LL;const int maxn = 1e5 + 5;int dp[maxn][2];int need[505], value[505];int main() { int n, V; while(scanf("%d%d", &n, &V) == 2) { for(int i = 1; i <= n; ++i) { scanf("%d%d", &need[i], &value[i]); } memset(dp, 0, sizeof(dp)); int f = 1; for(int i = 1; i <= n; ++i) { for(int j = 0; j <= V; ++j) { if(j < need[i]) dp[j][f] = dp[j][f^1]; else dp[j][f] = max(dp[j][f^1], dp[j-need[i]][f]+value[i]); } f ^= 1; } printf("%d\n", dp[V][f^1]); } return 0;}
如有不当之处欢迎指出!
阅读全文
0 0
- hihoCoder 1043 完全背包
- hihoCoder 1043 : 完全背包
- hihoCoder 1043 完全背包
- hihocoder -#1043 : 完全背包
- [HihoCoder]#1043 : 完全背包
- hihocoder #1043 : 完全背包
- hihocoder #1043 完全背包
- Hihocoder #1043 : 完全背包
- hihoCoder 1043 完全背包
- hihoCoder 1043 : 完全背包
- hihocoder 1043 : 完全背包
- hihocoder#1043之完全背包
- hihocoder 1043(完全背包)
- hihocoder #1043 : 完全背包 (DP)
- hihocoder:完全背包
- hihocoder 完全背包
- hihocoder-第七周-完全背包
- hiho一下 第七周 Hihocoder #1043 : 完全背包
- 构造N*N阶的方阵
- mysql_触发器
- 『ORACLE』 PLSQL—基本循环(11g)
- Linux c 网络编程
- 狼和羊的故事
- hihoCoder 1043 : 完全背包
- HDU 2027 统计元音
- mysql基础
- Intellij IDEA显示边侧栏maven等
- 『ORACLE』 PLSQL—case语句(11g)
- Qt5.7.0 mingw+qwtplot3D 编译
- Hibernate 缓存机制
- Intent(1)
- segment tree cf197D Xenia and Bit Operations