POJ 2063 Investment
来源:互联网 发布:二选一数据选择器芯片 编辑:程序博客网 时间:2024/05/23 01:17
http://poj.org/problem?id=2063
这道题是一道比较基础的完全背包问题,刚开始使用完全背包的思路套,RE了三次,MLE了一次,TLE了一次,后来看了看别人的优化,才知道自己原来是多笨了,竟然还用
三重循环,而且n都没有先除以1000就直接循环了,悲催。。。。。
思路是这样的,将总金额和每种债券的金额全都除以1000,然后再利用完全背包,求出要买的年限之内的利息,然后再将本金和利息相加就可以了
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=50000;
struct node
{
int p,v;
}a[20];
int dp[maxn];
int main()
{
int t,n,m,d;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
double amt=n*pow(1.1,(double)m)/1000;
scanf("%d",&d);
for(int i=0;i<d;i++)
{
scanf("%d%d",&a[i].p,&a[i].v);
a[i].p/=1000;
}
memset(dp,0,sizeof(dp));
for(int i=0;i<d;i++)
for(int j=a[i].p;j<=(int)amt+1;j++)
dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
for(int i=0;i<m;i++)
n+=dp[n/1000];
printf("%d\n",n);
}
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 背包
- 得到屏幕分辨率
- MyEclipse快捷键大全
- PHP 自定义函数
- 路径访问模式和模块访问控制器的关系
- this、super、static
- POJ 2063 Investment
- 指针类型转换
- Android开发环境搭建和SAP安装KEY计算程序
- Linux下如何使用Vi编辑器
- 感一名软件人员向公务员蜕变
- js 操作select和option
- Spring IOC初识
- VMware环境下用kgdb调试内核
- 大一总结,大二计划