HNU 12961 BitTorrent DP
题意:
你在网上下载东西,一个文件存储在一段或者多段里面,问怎么选择能在规定的流量内下载最多的文件数量。每段的大小一样。
思路:
习惯了做答案保存在DP数组里的题,做这种答案保存在下标里的题,转不过弯来。开始想过背包,但是一来内存不够,二来时间也不够。
其实是这样做的,dp[i][j][0/1]保存枚举到第i个,下载了j个,最后一个是否被下载的最小花费。 最后找花费没超过限制的最大值就好了。
最后值得注意的是,最后一段的时候,可能不会被p整除,不要算多了哦。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <cctype>
#include <time.h> using namespace std; const int INF = <<;
const int MAXN = ; int dp[MAXN][MAXN][]; //dp[i][j][k] 表示取到第i个,取了j个,的时候,第i个取或者不取
int a[MAXN];
int sum[MAXN]; //前缀和
int n, p, l; int main() {
#ifdef Phantom01
freopen("HNU12961.in", "r", stdin);
#endif //Phantom01 while (scanf("%d%d%d", &n, &p, &l)!=EOF) {
if (n==&&p==&&l==) break; sum[] = ;
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for (int i = ; i <= n; i++) sum[i] = sum[i-]+a[i];
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
dp[i][j][] = dp[i][j][] = INF;
dp[][][] = ; for (int i = ; i <= n; i++) {
for (int j= ; j <= i; j++)
dp[i][j][] = min(dp[i-][j][], dp[i-][j][]);
for (int j = ; j <= i; j++)
dp[i][j][] = min(dp[i-][j-][]-(sum[i-]/p)*p,
dp[i-][j-][]-((sum[i-]+p-)/p)*p)
+ (i==n ? sum[i] : ((sum[i]+p-)/p)*p);
}
int ans = ;
for (int i = ; i <= n; i++)
if (dp[n][i][]<=l || dp[n][i][]<=l)
ans = max(ans, i);
printf("%d\n", ans);
} return ;
}
HNU 12961 BitTorrent DP的更多相关文章
- dp - HNU 13404 The Imp
The Imp Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13404&cour ...
- HNU 13108-Just Another Knapsack Problem (ac自动机上的dp)
题意: 给你一个母串,多个模式串及其价值,求用模式串拼接成母串(不重叠不遗漏),能获得的最大价值. 分析: ac自动机中,在字典树上查找时,用dp,dp[i]拼成母串以i为结尾的子串,获得的最大价值, ...
- HNU OJ10086 挤挤更健康 记忆化搜索DP
挤挤更健康 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 339, A ...
- HNU 13108 Just Another Knapsack Problem DP + Trie树优化
题意: 给你一个文本串,和一些模式串,每个模式串都有一个价值,让你选一些模式串来组成文本串,使获得的价值最大.每个模式串不止能用一次. 思路: 多重背包,枚举文本串的每个位置和模式串,把该模式串拼接在 ...
- dp + 预处理前缀和 - HNU 13248 Equator
Equator Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13248&cour ...
- dp or 贪心 --- hdu : Road Trip
Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29 ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【KMP+DP】Count the string
KMP算法的综合练习 DP很久没写搞了半天才明白.本题结合Next[]的意义以及动态规划考察对KMP算法的掌握. Problem Description It is well known that A ...
- Kademlia、DHT、KRPC、BitTorrent 协议、DHT Sniffer
catalogue . 引言 . Kademlia协议 . KRPC 协议 KRPC Protocol . DHT 公网嗅探器实现(DHT 爬虫) . BitTorrent协议 . uTP协议 . P ...
随机推荐
- 学习es6 setter/getter研究
1.背景 在ES6中,我们对类的定义如下 class Person { // 构造函数 constructor (name) { // 属性初始化 this.name = name; } // 成员方 ...
- POJ 3190 Stall Reservations 【贪心 优先队列】
题意:给出n头牛必须单独占用一台机器的时间段,问至少需要多少台机器 先按照每头牛的时间的x来排序,然后用一个优先队列(优先选取最小的)维护已经喂好的牛的最小的结束时间 比如现在优先队列里面有m头牛已经 ...
- HDU 1950 Bridging signals【最长上升序列】
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...
- PHP————系统常量
PHP常量默认为大小写敏感.传统上常量标识符总是大写的. PHP常量名和其它任何 PHP 标签遵循同样的命名规则.合法的常量名以字母或下划线开始,后面跟着任何字母,数字或下划线.用正则表达式是这样表达 ...
- plsql 查询历史执行语句
control+e. 如果执行删除.修改.增加的操作,未提交的历史记录中也有.
- Intellij IDEA 2018.3激活破解方法(解决key is invalid)
1.程序安装包: https://download.jetbrains.8686c.com/idea/ideaIU-2018.3.exe 2.破解补丁:http://idea.lanyus.com/j ...
- 洛谷 P1967 货车运输 LCA + 最小生成树
两点之间边权最大值的最小值一定在图的最小生成树中取到. 求出最小生成树,进行倍增即可. Code: #include<cstdio> #include<algorithm> u ...
- MingW和cygwin的区别(转)
个人总结:读完这段文字需要5分钟 总结: MingW https://zh.wikipedia.org/wiki/MinGW Cygwin https://zh.wikipedia.org/wiki/ ...
- 紫书 例题8-5 UVa11054(等价转换)
这道题用到了等价转换的思想 所有要运到a1的酒, 都要经过a2, 所以不如把a2的值改成a1+a2,然后依次以此类推. #include<cstdio> #include<cmath ...
- [terry笔记]ogg_迁移同步实验_零停机
oracle golden gate我最近正在琢磨,这个软件我觉得约等于dataguard的逻辑模式,我认为其最大的优势是更可控制,比如可以细化到某个schema.某个table的同步. 如下实验的主 ...