Studious Little Jhool - HackerEarth- Dynamic Programming -Easy
Solution:-
using namespace std;
int arr[200],i;
void init()
{
for(int i=0;i<200;i++)
arr[i]=0;
}
int main()
{
int tc;
cin>>tc;
while(tc--)
{
int n,a,b;
cin>>n;
init();
arr[10]=1;
arr[12]=1;
for(i=13;i<=n;i++)
{
a=999;
b=999;
if(arr[i-10] || arr[i-12])
{if(arr[i-10])
a=arr[i-10];
if(arr[i-12])
b=arr[i-12];
arr[i]=1+min(a,b);}
}
if(arr[n])
cout<<arr[n];
else
cout<<"-1";
cout<<endl;
}
return 0;
}
No comments:
Post a Comment