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 ...
随机推荐
- class-metaclass-Class vs. type
In some languages, classes are only a compile-time feature (new classes cannot be declared at runtim ...
- Vue this.$router.push、replace、go的区别
1.this.$router.push 描述:跳转到不同的url,但这个方法会向history添加一个记录,点击后会返回到上一个页面 用法 //字符串 this.$router.push('home' ...
- BZOJ 1195 [HNOI2006]最短母串 (Trie图+状压+bfs最短路)
BZOJ1195 LOJ10061 题目大意:给你$n$个模式串,求一个最短且字典序最小的文本串并输出这个串,$n<=12,len<=50$ 首先对所有模式串构造$Trie$图,$Trie ...
- LAMP环境搭建备忘 -- MariaDB 安装(三)
因为 MySQL 的一些原因,在 Linux 平台上的开源数据库渐渐被 MariaDB 取代. MariaDB 安装命令如下图 安装成功后,接下来就启动这个数据库服务 我们还需要对数据库做一些初始化的 ...
- HTTP 文件共享服务器工具 - chfs
CuteHttpFileServer/chfs是一个免费的.HTTP协议的文件共享服务器,使用浏览器可以快速访问.它具有以下特点: 单个文件,整个软件只有一个可执行程序,无配置文件等其他文件 跨平台运 ...
- 超简单入门Vuex小示例
写在前面 本文旨在通过一个简单的例子,练习vuex的几个常用方法,使初学者以最快的速度跑起来一个vue + vuex的示例. 学习vuex需要你知道vue的一些基础知识和用法.相信点开本文的同学都具备 ...
- 使用JMX透过防火墙远程监控tomcat服务
https://my.oschina.net/mye/blog/64879 http://blog.csdn.net/l1028386804/article/details/51547408 http ...
- 安装spark问题汇总
使用的版本是 spark-1.6.3-bin-without-hadoop 运行spark-shell报错 运行spark-sql报错找不到org.datanucleus.api.jdo.JDOPer ...
- hdoj 3376,2686 Matrix Again 【最小费用最大流】
题目:hdoj 3376 Matrix Again 题意:给出一个m*n的矩阵,然后从左上角到右下角走两次,每次仅仅能向右或者向下,出了末尾点其它仅仅能走一次,不能交叉,每次走到一个格子拿走这个格子中 ...
- moble 设备多指手势识别 (tap , double_tap , pinch)
function(){ elem.addEventListener('touchstart', start , false) elem.addEventListener('touchend', end ...