hdu-5681 zxa and wifi(dp)
题目链接:
zxa and wifi
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
zxa was in charge of the planning of this project, and he was informed that the carriers were given two ways to set up the network. One way is using one wireless router and cables associated at the i-th family for some families network coverage, where the distance from the i-th family to each covered family (include the i-th family) is no more than ri , which needs ai costs. Another way is using one optical fiber cable at the i-th family for the i-th family network coverage, which needs bi costs.
zxa is interested to know, assuming that it is only permitted to use at most k wireless routers for network coverage in order to avoid too large Wi-Fi radiation, then what is the minimum cost for this n families network coverage, can you help him?
For each test case:
The first line contains two positive integers n and k.
The second line contains (n−1) positive integers, represent d1,d2,⋯,dn−1.
The next n lines, the i-th line contains three positive integers ai,ri and bi.
There is a blank between each integer with no other extra space in one line.
1≤T≤100,2≤n≤2⋅10^4,1≤k≤min(n,100),1≤ai,bi,di,ri≤10^5,1≤∑n≤10^5
//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
int inf=0x3f3f3f3f;
const int N=2e4+;
int n,k,a[N],b[N],sum[N],dis[N],l[N],r[N],d[N];
int dp[][N];
int main()
{
inf*=;
int t;
scanf("%d",&t);
while(t--)
{
mst(dp,inf);
scanf("%d%d",&n,&k);
sum[]=sum[]=;
Riep(n-)scanf("%d",&d[i]),sum[i+]=sum[i]+d[i];
Riep(n)scanf("%d%d%d",&a[i],&dis[i],&b[i]);
Riep(n)
{
int L=,R=i;
while(L<=R)
{
int mid=(L+R)>>;
if(sum[i]-sum[mid]>dis[i])L=mid+;
else R=mid-;
}
l[i]=L;
L=i,R=n;
while(L<=R)
{
int mid=(L+R)>>;
if(sum[mid]-sum[i]>dis[i])R=mid-;
else L=mid+;
}
r[i]=R;
}
for(int i=;i<=k;i++)dp[i][]=;
for(int i=;i<=n;i++)dp[][i]=min(dp[][i],dp[][i-]+b[i]);
for(int i=;i<=k;i++)
{
Rjep(n)
{
dp[i][j]=min(dp[i][j],dp[i][j-]+b[j]);
for(int x=l[j]-;x<=j;x++)
{
dp[i][r[j]]=min(dp[i][r[j]],dp[i-][x]+a[j]);
}
}
}
int ans=inf;
for(int i=;i<=k;i++)
{
ans=min(ans,dp[i][n]);
}
printf("%d\n",ans);
}
return ;
}
hdu-5681 zxa and wifi(dp)的更多相关文章
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- hdu 2829 Lawrence(斜率优化DP)
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...
- hdu 4568 Hunter 最短路+dp
Hunter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 1231.最大连续子序列-dp+位置标记
最大连续子序列 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)
HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包) 题意分析 裸的完全背包问题 代码总览 #include <iostream> #include <cstdio> ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- HDU 5682 zxa and leaf 二分 树形dp
zxa and leaf 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5682 Description zxa have an unrooted t ...
随机推荐
- 使用spring.net 1.3.2框架部署在虚拟目录上发生错误
如果你的网站使用了Spring.net 1.3.2,并部署在IIS的虚拟目录上,那么将会出现如下错误: The virtual path '/currentcontext.dummy' maps ...
- 一个优秀windows C++程序员的知识体系[转]
转自:一个优秀windows C++程序员的知识体系 思考一个优秀windows C++ 程序员该有哪些知识,可最终发现什么知识都不能少, 看下图: 除了上面知识,程序员还要不断学习, 保持对新知识的 ...
- Maven仓库的布局
任何一个构件都有其唯一的坐标,根据这个坐标可以定义其在仓库中的唯一存储路径,这便是Maven的仓库布局方式.例如log4j:log4j:1.2.15这一依赖,其对应的仓库路径为log4j/log4j/ ...
- ISO13485给企业带来的益处
1.ISO13485变强制性认证,日益受到欧美和中国政府机构的重视,有利于消除国际贸易中的技术壁垒,是进入国际市场的通行证: 2.提高和改善企业的管理水平,增加企业的知名度: 3.提高和保证产品的质量 ...
- HDU 5601 N*M bulbs 找规律
N*M bulbs 题目连接: http://codeforces.com/contest/510/problem/C Description NM个灯泡排成一片,也就是排成一个NM的矩形,有些开着, ...
- cdoj 80 Cube 水题
Cube Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/80 Descrip ...
- thinkphp关联查询
$list=$model->table("$dName d ,$mName m,$cName c") ->field('d.*,m.title as musicTitl ...
- 安卓高手之路之 WindowManager
安卓中的画面不是纯粹由window组成.而是改成了window+view的组织模式.window是一个顶层窗口的概念.view就相当于在window内的控件.而subwindow则是依附于window ...
- 【JavaScript】停不下来的前端,自动化流程
http://kb.cnblogs.com/page/501270/ 流程 关于流程,是从项目启动到发布的过程.在前端通常我们都做些什么? 切图,即从设计稿中获取需要的素材,并不是所有前端开发都被要求 ...
- DB2数据库性能优化介绍
DB2数据库性能优化介绍 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 前段时间,我从CSDN得到了这本书<DB2数据库性能调整和优化(第2版)& ...