bzoj2298: [HAOI2011]problem a dp
2015-03-20 08:31
239 查看
Description
一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低。”问最少有几个人没有说真话(可能有相同的分数)
Input
第一行一个整数n,接下来n行每行两个整数,第i+1行的两个整数分别代表ai、bi
Output
一个整数,表示最少有几个人说谎
Sample Input
3
2 0
0 2
2 2
Sample Output
1
HINT
100%的数据满足: 1≤n≤100000 0≤ai、bi≤n
dp计算出最多有多少人说真话就可以了。我们可以根据ai bi确定每个人所处在的区间,用map记下每个区间的人数
按每个的右边人数确定一类人。
很明显 这类人都说有r人比自己高 而l值不相同,所以他们最多只有一段相同的人说的是真话。
dp[i]代表前i种名次的人 最多有多少人
转移时要注意 说真话的可能是所有说法相同的人,也有可能是这个人所在的区间的最大值
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <vector> using namespace std; #define mp(a,b) make_pair(a,b) int getint() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; int f[100005]; vector<int> q[100005]; map<pair<int,int>,int> s; int main() { n=getint(); for(int i=1;i<=n;i++) { int a=getint(),b=getint(); int l=a+1,r=n-b; if(l>r)continue; s[mp(l,r)]++; if(s[make_pair(l,r)]==1) q[r].push_back(l); } for(int i=1;i<=n;i++) { f[i]=f[i-1]; for(int j=0;j<q[i].size();j++) { f[i]=max(f[i],f[q[i][j]-1]+min(s[mp(q[i][j],i)],i-q[i][j]+1)); } } printf("%d\n",n-f ); return 0; }
相关文章推荐
- bzoj 2302: [HAOI2011]Problem c(DP)
- BZOJ 2302: [HAOI2011]Problem c [DP 组合计数]
- 【BZOJ】【P2298】【HAOI2011】【problem a】【题解】【dp+二分】
- 【bzoj2302】【HAOI2011】【problem c】【dp】
- 【BZOJ2298】[HAOI2011]problem a DP
- BZOJ 2298 [HAOI2011]problem a DP
- BZOJ 2302: [HAOI2011]Problem c( dp )
- BZOJ2301: [HAOI2011]Problem b 莫比乌斯反演+容斥原理
- 2301: [HAOI2011]Problem b 莫比乌斯反演+前缀+容斥原理
- [HAOI2011]Problem b
- P2522 [HAOI2011]Problem b 莫比乌斯反演+除法优化
- Hdu 4089 Activation (概率dp) - 2011 ACM-ICPC Beijing Regional Contest Problem I
- bzoj2298: [HAOI2011]problem a(dp)
- BZOJ2298:[HAOI2011]problem a——题解
- [HAOI 2011]Problem b
- 2301: [HAOI2011]Problem b 莫比乌斯反演+前缀+容斥原理
- 【莫比乌斯反演+容斥】BZOJ2301-[HAOI2011]Problem b(成为权限狗的第一题纪念!)
- 【bzoj2301】[HAOI2011]Problem b 莫比乌斯反演
- [BZOJ2301][HAOI2011]Problem b(莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演)