hdu 4833 离散化+dp ****
先离散化,然后逆着dp,求出每个点能取到的最大利益,然后看有没有钱,有钱就投
想法好复杂
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
struct NN1
{
int d,e;
void input()
{
scanf("%d%d",&d,&e);
}
}node1[];
struct NN2
{
int start,finish;
int r;
void input()
{
scanf("%d%d%d",&start,&finish,&r);
}
}node2[];
int a[];
long long f[];
long long f2[];
int dp[]; vector<int>vec[];
vector<int>vec2[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
int n,m;
scanf("%d",&T);
while(T--)
{
iCase++;
printf("Case #%d:\n",iCase);
scanf("%d%d",&n,&m);
int cnt = ;
memset(f,,sizeof(f));
for(int i = ;i < n;i++)
{
node1[i].input();
//a[cnt++] = node1[i].d;
f[node1[i].d] += node1[i].e;
}
for(int i = ;i <= ;i++)
f[i] += f[i-];
for(int i = ;i < m;i++)
{
node2[i].input();
a[cnt++] = node2[i].start;
a[cnt++] = node2[i].finish;
}
sort(a,a+cnt);
cnt = unique(a,a+cnt) - a;
map<int,int>mp;
for(int i = ;i < cnt;i++)
mp[a[i]] = i;
f2[] = f[a[]];
for(int i = ;i < cnt;i++)
f2[i] = f[a[i]] - f[a[i-]];
for(int i = ;i < cnt;i++)
{
vec[i].clear();
vec2[i].clear();
}
for(int i = ;i < m;i++)
{
node2[i].start = mp[node2[i].start];
node2[i].finish = mp[node2[i].finish];
vec[node2[i].start].push_back(node2[i].finish);
vec2[node2[i].start].push_back(node2[i].r);
}
memset(dp,,sizeof(dp));
for(int i = cnt-;i >= ;i--)
{
dp[i] = dp[i+];
int sz = vec[i].size();
for(int j = ;j < sz;j++)
dp[i] = max(dp[i],dp[vec[i][j]] + vec2[i][j]);
}
long long ans ;
//minCostMaxflow(cnt,cnt+1,ans);
ans = ;
for(int i = ;i < cnt;i++)
{
ans += (long long)dp[i]*f2[i];
}
printf("%.2lf\n",(double)ans/); }
return ;
}
hdu 4833 离散化+dp ****的更多相关文章
- HDU 2836 (离散化DP+区间优化)
Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...
- hdu 4123 树形DP+RMQ
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
随机推荐
- Graphtree--zabbix增强功能(一屏展示所有内容)
Graphtree--zabbix增强功能 Graphtree由OneOaaS开发并开源出来. 功能 集中展示所有分组设备 集中展示一个分组图像 集中展示一个设备图像 展示设备下的Applicatio ...
- destroy-method="close"的作用
destroy-method="close"的作用是当数据库连接不使用的时候,就把该连接重新放到数据池中,方便下次使用调用.
- WPF 获取IP地址
List<string> ipList = new List<string>(); foreach (IPAddress _IPAddress in Dns.GetHostEn ...
- derby数据库操作比较难理解的错误及解决方法大全
一.插入(INSERT时报错) 1.错误:java.sql.SQLIntegrityConstraintViolationException: 列“test”无法接受空值. 可能原因:建表时test列 ...
- linux命令别名的使用
语 法:alias[别名]=[指令名称] 1,查看该用户下的别名: alias 2,有的系统里没有ll这个命令,原因就是没有定义ll='ls -l --color=tty'这个别名 如果想永久生效,就 ...
- ubuntu查看版本命令
有两种方法 1,cat /etc/issue 2,sudo lsb_release -a 这个查询出来的结果比上面的那个全一些.
- 转 XenServer、XenCenter安装测试
本文转自:http://blog.sina.com.cn/s/blog_5611597901014ze4.html 系统环境:win7 64bit vmware-8.0.1 镜像文件:XenServ ...
- Linux 中的 wheel 组和 staff 组
wheel 组的概念 wheel 组的概念继承自 UNIX.当服务器需要进行一些日常系统管理员无法执行的高级维护时,往往就要用到 root 权限:而“wheel” 组就是一个包含这些特殊权限的用户池: ...
- Sql分隔字符串方法--split
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --DEClARE @str varchar(500)='a,b2,v5,d3,ew,2,3,dd' ...
- Unity游戏开发之“屏幕截图”
原地址:http://sygame.lofter.com/post/117105_791680 在unity游戏开发中,可能会遇到在游戏中截屏的效果.这儿提供两种截屏方法.(方法二提供显示截图缩略图代 ...