hdu 1963 Investment 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963
题目意思:有 本金 money,还有一些股票的种类,第 i 种股票买入需要 value[i] 这么多钱,相应会有一定的利息interest[i],问经过若干年 year 后,每年都以最优的方案投资,总的资金有多少?
完全背包题,不过要看清楚 这句话:The value of a bond is always a multiple of $1 000,否则TLE了
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; const int maxn = 1e6 + ; typedef long long ll;
int value[maxn], interest[maxn];
ll dp[maxn], ans, money, tolmoney; int main()
{
int kind, tcase, year;
while (scanf("%d", &tcase) != EOF)
{
while (tcase--)
{
scanf("%lld%d", &money, &year);
scanf("%d", &kind);
for (int i = ; i < kind; i++)
{
scanf("%d%d", &value[i], &interest[i]);
value[i] /= ;
}
memset(dp, , sizeof(dp));
ans = , tolmoney = money;
for (int j = ; j < year; j++)
{
if (j != )
money = tolmoney;
money /= ;
for (int i = ; i < kind; i++)
{
for (int k = value[i]; k <= money; k++)
{
dp[k] = max(dp[k], dp[k-value[i]] + interest[i]);
ans = max(dp[k], ans);
}
}
tolmoney += ans;
}
printf("%lld\n", tolmoney);
}
}
return ;
}
hdu 1963 Investment 解题报告的更多相关文章
- hdu 1963 Investment 多重背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 //多重背包 #include <cstdio> #include <cstr ...
- [HDU 1963] Investment
Investment Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descrip ...
- Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...
- BestCoder27 1001.Jump and Jump... (hdu 5162) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5162 题目意思:有 n 个 kid,每个 kid 有三个成绩 a, b, c.选最大的一个成绩作为这个 ...
- BestCoder27 1002.Taking Bus(hdu 5163) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5163 题目意思:有 n 个车站,给出相邻两个车站的距离,即车站 i 和车站 i+1 的距离为 di ( ...
- BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...
- BestCoder14 1002.Harry And Dig Machine(hdu 5067) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5067 题目意思:给出一个 n * m 的方格,每一个小方格(大小为1*1)的值要么为 0 要么为一个正 ...
随机推荐
- net3:Button的CommandName使用,AdRotator,BulletedList的使用
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- apxs添加apache模块
根phpize很类似,可以用apxs为Apache打模块: 要使用apxs,你的平台必须支持DSO特性, 而且Apache的httpd必须内建了mod_so模块.查看一下 httpd -l | gre ...
- Scrapy学习-9-FromRequest
用FromRequest模拟登陆知乎网站 实例 默认登陆成功以后的请求都会带上cookie # -*- coding: utf-8 -*- import re import json import d ...
- hdu3987,最小割时求最少割边数
题意:求最小割时候割边最少的数量.算法:先求dinic一遍,跑出残网络,再把该网络中满流量(残量为0)的边 残量改为1,其他边残量改为无穷,则再跑一次最大流,所得即为答案.(思,最小割有喝多组,但是要 ...
- BZOJ 1878 [SDOI2009]HH的项链 (主席树 或 莫队算法)
题目链接 HH的项链 这道题可以直接上主席树的模板 #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) ...
- Mac Ubuntu ----端口被占用
Mac下使用lsof(list open files)来查看端口占用情况,lsof 是一个列出当前系统打开文件的工具. 使用 lsof 会列举所有占用的端口列表: 1 $ lsof 使用less可以用 ...
- hadoop优质链接
http://wiki.apache.org/hadoop/FAQ
- Js学习第十天----函数
函数 什么是函数?函数是由事件驱动的或者当他被调用时运行的可反复使用代码块.预计没明确,个人觉得函数就是能完毕一个功能的代码块. 看个案例: <!DOCTYPE html> <htm ...
- libxml/HTMLparser.h file not found
在导入asihttprequest包时出问题导入了libxml2.dylib.可是却提示libxml/HTMLparser.h file not found. 这是由于你的开发环境默认的路径无法找到这 ...
- POJ 2524 Ubiquitous Religions (幷查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23090 Accepted: ...