poj 2063 Investment
来源:互联网 发布:c语言简单编程题目 编辑:程序博客网 时间:2024/06/06 02:44
简单DP,练练手就ok,千万别沉迷其中,嘿嘿。
题意:给你一笔钱,叫你去投资,每年的收益又可以拿去继续投,问你n年后你最多有多少钱。
思路:那里说的那个所以得bond都是1000的倍数,这个很重要,不然应该会超时的,直接将不足1000的部分用last来存储,因为对投资无用,mon存储现在有多少个1000,然后就是一个纯完全背包问题。dp数组的大小自己可以用计算机算下 1.1^40然后乘上原始成本,是46点几倍吧,所以数组跟我开这样大,代码很清晰,看吧。
#include<cstdio>#include<cstring>#include<iostream>#define max(a1,b1) (a1)>(b1)?(a1):(b1)using namespace std;long long cost[11],wei[11],mon,year,last,dp[50000];int n;int main(void){ int test; cin>>test; while(test--) { cin>>mon>>year; cin>>n; last = mon%1000; mon /= 1000; for(int i=1;i<=n;++i) {cin>>wei[i]>>cost[i]; wei[i] /= 1000; } for(int y=1;y<=year;++y) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;++i) //完全背包 { for(int v=wei[i];v<=mon;++v) { dp[v] = max(dp[v],dp[v-wei[i]]+cost[i]); } } last += dp[mon]; mon += (last/1000); last %= 1000; } mon *= 1000; mon += last; cout<<mon<<endl; } return 0;}
- 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 4514 湫湫系列故事——设计风景线
- 1039. Anniversary Party (dp)
- 如何在ashx页面获取Session值
- C#中Const与Static Readonly的区别
- python程序的执行过程
- poj 2063 Investment
- 华为推SAP HANA认证、基于华为服务器的一体机解决方案
- org.apache.log4j.Logger 详解
- js判断当前页面是http还是https
- 二维码——超越传统地理位置的定位新利器
- WeakReference and WeakHashMap
- 【jiasuba】教你利用Win 7画中画窗口,酷爱壁纸随心换
- ARM LR寄存器
- HDU Fire Net