ACODE - Alphacode editorial SPOJ - Dynamic Programming - Unleash-Coding-Skills

Saturday, 2 June 2018

ACODE - Alphacode editorial SPOJ - Dynamic Programming

ACODE - Alphacode

This is solution for ACODE - Alphacode This is Dynamic Programming Problem.

The link for this problem is:


The CPP solution for  ACODE - Alphacode SPOJ is :

      #include <iostream>
      #include <algorithm>
      #include <cstring>
      #include <string>
      using namespace std;

      int main() {
      int dp[5003],i,j,k,sum;
      string s;
      cin>>s;
      while(s[0]!='0')
      {
          memset(dp,0,sizeof dp);
          dp[0]=1;
          i=1;
           int len=s.length();
          while(i<len){
              sum=(s[i-1]-'0')*10;
              k=s[i]-'0';
              sum+=k;
             
              if(k>0)
              {
                  dp[i]+=dp[i-1];
              }
              if(sum>9&&sum<=26)
              {
              dp[i]+=dp[i-2<0?0:i-2];
              }
              i++;
          }
        cout<<dp[len-1]<<endl;
          cin>>s;
      }
      return 0;
      }

Other latest Problems in SPOJ:

DIVSTR - Divisible Strings :  http://www.spoj.com/problems/DIVSTR/

Happy Coding..................



Tags:

ACODE - Alphacode editorial,ACODE - Alphacode editorial SPOJ,ACODE - Alphacode solution,ACODE - Alphacode dynamic programming,dynamic programming example




No comments:

Post a comment