HDU 1677 Nested Dolls
2015-02-17 21:21
363 查看
俄罗斯套娃,套娃有高和宽,可以套在一起,要使套娃个数尽量少。
做法:对宽和高进行排序然后转化成最长不下降子序列问题。
做法:对宽和高进行排序然后转化成最长不下降子序列问题。
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; struct p { int w,h; }; p a[20010]; int dp[20010]; bool comp(p a, p b) { if(a.w == b.w)//如果w相等,再对h升序排列 return a.h < b.h; return a.w > b.w;//先对w降序排序 } int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for (int i = 0 ; i < n ; i++) { scanf("%d %d",&a[i].w,&a[i].h); } memset(dp,0,sizeof(dp)); sort(a,a+n,comp); int j,k; j = 0; for(int i = 0 ; i < n; i++) { for(k = j ; k >=0 ; k--) { if(dp[k]<=a[i].h) { dp[++k] = a[i].h; break; } } j = max (j,k); } printf("%d\n",j); } return 0; }
相关文章推荐
- hdu 1677 Nested Dolls
- hdu 1677 Nested Dolls
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls (贪心)
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls(排序+二分)
- UVA 11368 & POJ 3636 & HDU 1677 Nested Dolls(贪心 + 二分LIS)
- hdu 1677 Nested Dolls 子串
- HDU 1677
- HDU 1677 二分法进行判断
- hdu----(1677)Nested Dolls(DP/LIS(二维))
- hdu 1677
- hd 1677 Nested Dolls
- hdu 1677 Nested Dolls LIS + 动态规划
- 【HDU 1275 && HDU 1677】 两题类似,经典 DP。
- hdu 1677 (dp)
- HDU - 1677Nested Dolls最长上升子序列变式