Welcome to code jam problem: https://code.google.com/codejam/contest/90101/dashboard#s=p2
I have been trying to solve this but have been unable to do so. I think my logic is correct and the dp is right but there is something wrong with my implementation. Suggestions are welcome. Thanks!
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main() {
int t;
cin>>t;
char str[51] = {"welcome to code jam"};
str[19]='\0'; //Needed?
while(t--)
{
char inp[501];
gets(inp);
int dp[20][501];
for(int i = 0;i<20;i++)
{
for(int j =0;j<501;j++)
dp[i][j]=0;
}
for(int i = 0;i<501;i++)
{
dp[0][i]=1;
}
for(int i = 0;i<20;i++)
{
dp[i][0]=0;
}
for(int i = 0;i<20;i++)
{
for(int j = 0;j<=strlen(inp);j++) //Correct?
{
if(str[i]==inp[j])
{
dp[i+1][j+1]+=dp[i][j]+dp[i+1][j];
}else
{
dp[i+1][j+1]=dp[i+1][j];
}
}
}
int u =strlen(inp);
cout<<dp[19][u]<<endl;
}
return 0;
}