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 ...
随机推荐
- 如何给table的指定td进行css样式改变
td:nth-child(){background-color:#; color:#fff;}/*把第3个td的背景设为黑色*/ :nth-child()不止可以给table指定样式 p标签页是可以的 ...
- Thread Control Block
Thread Control Block The following is the declaration of the Thread Control Block. struct tcb { u32_ ...
- 3ds Max绘制一个漂亮的青花瓷碗3D模型
这篇教程向小伙伴门介绍使用3ds Max绘制一个漂亮的青花瓷碗3D模型方法,教程很不错,很适合大家学习,推荐过来,一起来学习吧! 车削,材质贴图的应用,添加位图,渲染视图 步骤如下: 在桌面找到3DM ...
- C#网络编程—HTTP应用编程(转)
https://www.cnblogs.com/huangxincheng/archive/2012/01/09/2316745.html https://www.cnblogs.com/wangqi ...
- [SDOI2008]沙拉公主的困惑 线性筛_欧拉函数_逆元_快速幂
Code: #include<cstdio> using namespace std; typedef long long ll; const int maxn=10000000+1; l ...
- 路飞学城Python-Day4(practise)
#1.请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li = ['alex','eric','rain']# li = ['alex','eric','rain']# print('_'.j ...
- 微信小程序 分享海报
const app = getApp(); const template = require('../../template/templates.js'); Page({ /** * 页面的初始数据 ...
- 紫书 例题8-4 UVa 11134(问题分解 + 贪心)
这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...
- 紫书 习题8-12 UVa 1153(贪心)
本来以为这道题是考不相交区间, 结果还专门复习了一遍前面写的, 然后发现这道题的区间是不是 固定的, 是在一个范围内"滑动的", 只要右端点不超过截止时间就ok. 然后我就先考虑有 ...
- Mysql学习总结(22)——Mysql数据库中制作千万级测试表
前言: 为了方便测试性能.分表等工作,就需要先建立一张比较大的数据表.我这里准备先建一张千万记录用户表. 步骤: 1 创建数据表(MYISAM方式存储插入速度比innodb方式快很多) 数据表描述 数 ...