Wikipedia

Search results

Wednesday 10 December 2014

SPOJ 18240. GENIE SEQUENCE (KURUK14)

/http://www.spoj.com/problems/KURUK14/

simple DP it is...........C++ code goes  here:




#include <bits/stdc++.h>
using namespace std;
int main()
{
 int t;     
cin>>t;   
 while(t--)    
 {
  int n,i,flag=0,x;
  cin>>n;    
 int a[1001]={0};
  for(i=0;i<n;i++)
  {
  cin>>x;    
  if(a[x+1]==0) 
  {
   a[x+1]=1;    
   flag++;     
  }
  else if(a[n-x]==0)                
  {
   a[n-x]=1;      
   flag++;        
  }
  }
  if(flag==n)                
  {
  printf("YES\n");
  }
  else                
  {
  printf("NO\n");
  }
 }
 return 0;
}


 

No comments:

Post a Comment