poj 2063Investment
来源:互联网 发布:php 源代码 登录 权限 编辑:程序博客网 时间:2024/06/05 17:48
#include<iostream>#include<fstream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int t;int init,year, d;struct stock{int v;int p;};stock s[15];int f[45300];int main(){//freopen("1.txt","r",stdin);int cinit;scanf("%d",&t);while(t--){memset(s,0,sizeof(s));scanf("%d%d%d",&init, &year,&d);for(int i = 1; i <= d; ++i){scanf("%d%d",&s[i].v,&s[i].p);s[i].v /= 1000;}//每年更新initwhile(year--){cinit = init / 1000;memset(f,0,sizeof(f));for(int i = 1; i <= d; ++i){for(int j = s[i].v ; j <= cinit; ++j){if(f[j-s[i].v] + s[i].p > f[j]){f[j] = f[j-s[i].v]+s[i].p;} //背包装满}}init += f[cinit];}printf("%d\n",init);}return 0;}
这道题的关键是对于给定数据的优化~
还有就是f数组不要开得太大,否则会tle;
开始以为是因为定义了struct,后来请教了高人才明白是数组开得大了~
- poj 2063 Investment
- POJ 2063 Investment
- poj 2063 Investment
- POJ 2063 Investment
- POJ 2063 Investment
- poj 2063 Investment
- Poj 2063 Investment
- poj 2063Investment
- POJ 2063 Investment
- POJ 2063 Investment
- poj 2063 Investment
- poj 2063 Investment
- POJ 2063 Investment
- POJ 2063 Investment
- poj 2063 Investment
- Poj 2063 Investment
- POJ--2063--Investment--背包
- poj 2063 Investment 背包
- HDU 1279验证角谷猜想
- 使用json-lib进行Java和JSON之间的转换
- NoSQL数据库:Redis内存使用优化与存储
- Centos搭建SVN服务器三步曲
- VIM 配置文件
- poj 2063Investment
- python random模块
- Jenkins Maven打包出错异常的解决方法
- raid 2.0的理解
- java.policy 文件格式及使用方法
- Matlab GUI设计笔记
- SQL 序列
- String转换为json对
- 在开机的时候,执行想要的 shell script