Problem Type : DP (LIS)
#include<stdio.h>
#include<string.h>
int main() /// Longest Increasing Subsequence :D
{
long int arr[10000],n,i,j,p,arr1[10000],s,q,m,c=0;
//scanf("%d",&n);
while(true)
{
c++;
i=1;
scanf("%ld",&m);
if(m==-1)
break;
while(true)
{
arr[i]=m;
scanf("%ld",&m);
if(m==-1)
break;
i++;
}
n=i;
for(i=1; i<=n; i++)
{
arr1[i]=1;
}
s=1;
for(i=1; i<=n; i++)
{
for(j=1; j<i; j++)
{
if(arr[j]>arr[i])
{
p=arr1[j]+1;
if(p>arr1[i])
{
arr1[i]=p;
if(s<p)
{
s=p;
}
}
}
}
}
if(c!=1)
printf("\n");
printf("Test #%ld:\n",c);
printf(" maximum possible interceptions: %ld\n",s);
memset(arr,0,sizeof (arr));
memset(arr1,0,sizeof(arr1));
}
}
#include<stdio.h>
#include<string.h>
int main() /// Longest Increasing Subsequence :D
{
long int arr[10000],n,i,j,p,arr1[10000],s,q,m,c=0;
//scanf("%d",&n);
while(true)
{
c++;
i=1;
scanf("%ld",&m);
if(m==-1)
break;
while(true)
{
arr[i]=m;
scanf("%ld",&m);
if(m==-1)
break;
i++;
}
n=i;
for(i=1; i<=n; i++)
{
arr1[i]=1;
}
s=1;
for(i=1; i<=n; i++)
{
for(j=1; j<i; j++)
{
if(arr[j]>arr[i])
{
p=arr1[j]+1;
if(p>arr1[i])
{
arr1[i]=p;
if(s<p)
{
s=p;
}
}
}
}
}
if(c!=1)
printf("\n");
printf("Test #%ld:\n",c);
printf(" maximum possible interceptions: %ld\n",s);
memset(arr,0,sizeof (arr));
memset(arr1,0,sizeof(arr1));
}
}
No comments:
Post a Comment