#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[10000];
ll dp[40000];
ll n;
ll solve(ll i)
{
if(i==n)
return 0;
if(dp[i]!=-1)
return dp[i];
ll cnt=0,mx=0;
for(ll j=i+1;j<n;j++)
{
if(arr[i]>=arr[j])
{
ll tmp=solve(j);
if(tmp>mx)
{
mx=tmp;
}
}
}
dp[i]=1+mx;
return dp[i];
}
int main()
{
//ofstream o("op.txt");
ll i,j,k=1,l,m;
memset(dp,-1,sizeof(dp));
while(1)
{
memset(arr,0,sizeof(arr));
cin>>m;
if(m==-1)
break;
else
{
arr[0]=999999999;
arr[1]=m;
i=2;
while(1)
{
cin>>m;
if(m==-1)
break;
arr[i]=m;
i++;
}
n=i;
}
memset(dp,-1,sizeof(dp));
if(k!=1)
cout<<endl;
cout<<"Test #"<<k<<":"<<endl;
cout<<" maximum possible interceptions: "<<solve(0)-1<<endl;
k++;
}
return 0;
}
using namespace std;
typedef long long ll;
ll arr[10000];
ll dp[40000];
ll n;
ll solve(ll i)
{
if(i==n)
return 0;
if(dp[i]!=-1)
return dp[i];
ll cnt=0,mx=0;
for(ll j=i+1;j<n;j++)
{
if(arr[i]>=arr[j])
{
ll tmp=solve(j);
if(tmp>mx)
{
mx=tmp;
}
}
}
dp[i]=1+mx;
return dp[i];
}
int main()
{
//ofstream o("op.txt");
ll i,j,k=1,l,m;
memset(dp,-1,sizeof(dp));
while(1)
{
memset(arr,0,sizeof(arr));
cin>>m;
if(m==-1)
break;
else
{
arr[0]=999999999;
arr[1]=m;
i=2;
while(1)
{
cin>>m;
if(m==-1)
break;
arr[i]=m;
i++;
}
n=i;
}
memset(dp,-1,sizeof(dp));
if(k!=1)
cout<<endl;
cout<<"Test #"<<k<<":"<<endl;
cout<<" maximum possible interceptions: "<<solve(0)-1<<endl;
k++;
}
return 0;
}
No comments:
Post a Comment