BZOJ 2298: [HAOI2011]problem a 动态规划
2298: [HAOI2011]problem a
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=2298
Description
一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低。”问最少有几个人没有说真话(可能有相同的分数)
Input
第一行一个整数n,接下来n行每行两个整数,第i+1行的两个整数分别代表ai、bi
Output
一个整数,表示最少有几个人说谎
Sample Input
3
2 0
0 2
2 2
Sample Output
HINT
100%的数据满足: 1≤n≤100000 0≤ai、bi≤n
题意
题解:
转换一下,就是求最多有多少个人满足题意
dp[i]表示前i名最多有多少个人没有说谎
那么dp[i]=max(dp[i],dp[j]+sum[j+1][i])其中sum(j+1](i)表示赞同这个区间的人数
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* struct node
{
int l,r;
};
vector<int> Q[maxn];
map<pair<int,int> ,int> H;
int dp[maxn];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
int x=read(),y=read();
if(x+y>=n)continue;
x++,y=n-y;
if(!H[make_pair(x,y)])Q[y].push_back(x);
H[make_pair(x,y)]++;
if(H[make_pair(x,y)]>y-x+)H[make_pair(x,y)]=y-x+;
}
for(int i=;i<=n;i++)
{
dp[i]=dp[i-];
for(int j=;j<Q[i].size();j++)
dp[i]=max(dp[i],dp[Q[i][j]-]+H[make_pair(Q[i][j],i)]);
}
printf("%d\n",n-dp[n]);
}
BZOJ 2298: [HAOI2011]problem a 动态规划的更多相关文章
- BZOJ 2298: [HAOI2011]problem a【动态规划】
Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n,接下来n行每行两个 ...
- bzoj 2298: [HAOI2011]problem a
Description 一次考试共有n个人参加,第i个人说:"有ai个人分数比我高,bi个人分数比我低."问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n ...
- 【BZOJ 2298】 2298: [HAOI2011]problem a (DP)
2298: [HAOI2011]problem a Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1326 Solved: 637 Descript ...
- Bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演+除法分块)
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Description 对于给出的n个询问,每次求有多少个数对(x, ...
- bzoj 2301: [HAOI2011]Problem b
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Submit: 3757 Solved: 1671 [Submit] ...
- BZOJ 2301: [HAOI2011]Problem b 莫比乌斯反演
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 1007 Solved: 415[Submit][ ...
- BZOJ 2302: [HAOI2011]Problem c( dp )
dp(i, j)表示从i~N中为j个人选定的方案数, 状态转移就考虑选多少人为i编号, 然后从i+1的方案数算过来就可以了. 时间复杂度O(TN^2) ------------------------ ...
- BZOJ 2301: [HAOI2011]Problem b( 数论 )
和POI某道题是一样的... http://www.cnblogs.com/JSZX11556/p/4686674.html 只需要二维差分一下就行了. 时间复杂度O(MAXN + N^1.5) - ...
- BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 6519 Solved: 3026[Submit] ...
随机推荐
- 两个STL网址 总结的很好 && c++堆的网址
http://www.cnblogs.com/bigcat814/ http://blog.sina.com.cn/s/blog_7065a9de010154ve.html 堆 http://www. ...
- bzoj1079: [SCOI2008]着色方案
dp.以上次染色时用的颜色的数量和每种数量所含有的颜色作状态. #include<cstdio> #include<algorithm> #include<cstring ...
- [POJ 2461] Billiard
同swustoj 11 Billiard Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1362 Accepted: 8 ...
- RPi 2B 自动发送获取的IP到固定邮箱
/************************************************************************* * RPi 2B 自动发送获取的IP到固定邮箱 * ...
- android利用WebView实现浏览器的封装
android提供了封装浏览器的接口,可以让开发者利用自己的view显示网页内容.今天又实现研究了一下,利用WebView显示浏览器内容,还可以利用 WebViewClient显示自己需要的内容. 参 ...
- android ListView详解
转自:http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html 在android开发中ListView是比较常用的组件,它以列表的形式展 ...
- HDU 3586-Information Disturbing(树形dp)
题意: n个节点的通信连接树,切断每个边有一定的花费,要你切断边,在总花费不超过m的前提,使所有的其他节点都不能和节点1(根)连通,切边时有花费上限,让你最小化这个上限. 分析:最小化最大值,想到二分 ...
- 卸载sql server 2012
好不容易装上了sql server 2012数据库,可是却不能连接本地的数据库,后来发现缺少一些服务,于是决定重新安装,但是卸载却很麻烦,如果卸载不干净的话,重新安装会出问题,所以下面就总结一些方法: ...
- 屏蔽同步(JAVA)
以全球气候预测程序为例.这些程序通过将地球分为许多单元,在每个循环中,每个单元的计算都是隔离进行的,直到这些值趋于稳定,然后相邻单元之间就会交换一些数据.所以,从本质上讲,在每个循环中各个线程都必须等 ...
- 【windows核心编程】 第六章 线程基础
Windows核心编程 第六章 线程基础 欢迎转载 转载请注明出处:http://www.cnblogs.com/cuish/p/3145214.html 1. 线程的组成 ① 一个是线程的内核 ...