hdu 1160 FatMouse's Speed
2014-07-21 10:27
417 查看
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9028 Accepted Submission(s): 4006
Special Judge
[align=left]Problem Description[/align]
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing,
but the speeds are decreasing.
[align=left]Input[/align]
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information
for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
[align=left]Output[/align]
Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],...,
m
then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m
]
and
S[m[1]] > S[m[2]] > ... > S[m
]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
[align=left]Sample Input[/align]
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
[align=left]Sample Output[/align]
4
4
5
9
7
题意是找出按w升序且s降序的最长序列。首先把整个排序,按体重升序,速度降序,然后再dp求解。
AC代码
#include<stdio.h> #include<string.h> #include<algorithm> #define maxn 1005 using namespace std; typedef struct { int x,y; int id; }node; node a[maxn]; int dis[maxn]; int dp[maxn]; int ans[maxn]; int cmp(node a,node b) { if(a.x==b.x) return a.y>b.y; return a.x<b.x; } int main() { //freopen("in.txt","r",stdin); int n=0; while(scanf("%d %d",&a .x,&a .y)!=EOF) { a .id=n+1; dp =1; dis =0; n++; } memset(ans,0,sizeof(ans)); sort(a,a+n,cmp); // for(int i=0;i<n;i++) // printf("%d ",a[i].id); int tot=0; int flag=0; for(int i=0;i<n;i++) { for(int j=0;j<i;j++) { if(a[i].x>a[j].x&&a[i].y<a[j].y&&dp[i]<dp[j]+1) //状态转移 { dp[i]=dp[j]+1; dis[i]=j; if(dp[i]>tot) { tot=dp[i]; flag=i; } } } } int k=flag; int cnt=0; while(k!=0) { ans[cnt++]=k; k=dis[k]; } printf("%d\n",cnt); while(cnt>0) { cnt--; printf("%d\n",a[ans[cnt]].id); } return 0; }
相关文章推荐
- FatMouse's Speed HDU - 1160
- HDU 1160 FatMouse's Speed(求最长递减序列+记录路径)
- HDU_1160_FatMouse's Speed
- 每日三题-Day4-A(HDU 1160 FatMouse's Speed 最长有序子序列)
- hdu 1160 FatMouse's Speed dp
- [HDU1160]-FatMouse's Speed
- HDU 1160 FatMouse's Speed (最长上升子序列+路径输出)
- HDU1160——FatMouse's Speed
- (HDU - 1160)FatMouse's Speed(DP)
- hdu1160--fatmouse.speed
- hdu1160 FatMouse's Speed--DP&记录路径
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- FatMouse's Speed HDU - 1160 --dp的路径记忆问题
- hdu 1160 FatMouse's Speed(动态规划)
- 基础dp9-- J - FatMouse's Speed HDU - 1160
- HDU - 1160 —— FatMouse's Speed —— dp
- HDU1160_FatMouse's Speed【LIS变形】
- J - FatMouse's Speed HDU 1160 (动态规划,最长上升子序列+路径输出)
- hdu-1160 FatMouse's Speed
- HDU 1160 FatMouse's Speed(LIS)