POJ 2063【完全背包】
来源:互联网 发布:js里的数组去重 编辑:程序博客网 时间:2024/06/05 08:25
这道题就是需要每年都进行一次动态规划,然后直接套完全背包即可
因为本金有可能很大,所以这里面有一个简易的状态压缩,因为本金和价格都是的1000倍数,可以将其都除以1000;
#include<stdio.h>#include<string.h>int max( int a, int b){return a > b ? a : b;}int main(void){int t, j, i, y, num, basic, year;int dp[200005], value[20], profit[20], sum;scanf("%d", &t);while(t--){scanf("%d%d", &basic, &year);scanf("%d", &num);for( i = 1; i <= num; i++){scanf("%d%d", &value[i], &profit[i]);value[i] /= 1000;} for( y = 1; y <= year; y++){sum = basic / 1000;// 状态压缩 memset( dp, 0, sizeof(dp));for( i = 1; i <= num; i++){for( j = value[i]; j <= sum; j++)dp[j] = max( dp[j], dp[j-value[i]]+profit[i]);}basic += dp[sum];}printf("%d\n", basic);}return 0;}
0 0
- POJ 2063 完全背包
- poj 2063 完全背包
- poj-2063-完全背包
- poj 2063完全背包
- POJ-2063 完全背包
- POJ 2063【完全背包】
- poj 2063 完全背包
- poj 2063 完全背包
- poj 2063 Investment 完全背包
- Poj 2063 Investment (完全背包)
- poj 2063 投资 完全背包
- POJ 2063 Investment 完全背包
- poj 2063 Investment 完全背包
- poj 2063 Investment (完全背包)
- poj 2063 多次完全背包
- POJ 2063 Investment 完全背包
- POJ 2063 Investment 完全背包
- POJ 2063 Investment (完全背包)
- 5555555555555555555555555
- 5555555555555555555555555
- 5555555555555555555555555
- APP快速开发:用这些工具更给力
- 在树莓派上用python控制LED
- POJ 2063【完全背包】
- 序列帧的使用(汤姆猫为例)
- sizeclassing + autolayout分类自动布局
- selenium+Python 实现简单的网页测试
- Android夜间模式实现
- 字符集和字符编码(Charset & Encoding)
- Codeforces Round #305 (Div. 2)C---Mike and Frog(扩欧+乱搞)
- openwrt 运行程序时提示缺少libstdc++.so.6
- scala的一些例子