FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13133 Accepted Submission(s): 5778
Special Judge
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.
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
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.
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max 10005
int dp[Max],t[Max],ans[Max];
struct node
{
int s,w,n;
}a[Max];
bool cmp(node x,node y)
{
return x.w<y.w;
}
int main()
{
int num;
int i=,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&a[i].w,&a[i].s)!=EOF)
{
a[i].n=i;
i++;
}
num=i-;
sort(a+,a+num+,cmp);
/* for(i=1;i<=num;i++)
{
cout<<a[i].w<<" "<<a[i].s<<" "<<a[i].n<<endl;
}*/
for(i=;i<Max;i++)
{
dp[i]=;
t[i]=;
}
for(i=;i<=num;i++)
{
for(j=;j<i;j++)
{
if(a[i].s<a[j].s&&a[i].w!=a[j].w&&(dp[j]+)>dp[i])
{
dp[i]=dp[j]+;
t[i]=j;
}
}
}
int maxn=dp[num],index=num;
for(i=;i<=num;i++)
if(dp[i]>maxn)
{
index=i;
maxn=dp[i];
}
ans[maxn]=a[index].n;
// cout<<ans[maxn]<<endl;
index=t[index];
for(i=maxn-;i>=;i--)
{
ans[i]=a[index].n;
// cout<<ans[i]<<endl;
index=t[index];
}
cout<<maxn<<endl;
for(i=;i<=maxn;i++)
cout<<ans[i]<<endl;
}