ANARC05H - Chop Ahoy! Revisited!
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char str[26];
int len, sum;
int solve(int pos, int prevSum)
{
if(pos == len)
return 1;
int c = 0;
for(int i = pos, sum = 0; i < len; i++)
{
sum += str[i] - '0';
if(sum >= prevSum)
{
c += solve(i + 1, sum);
}
}
return c;
}
int main()
{
int k = 1;
while(true)
{
scanf("%s", str);
if(!strcmp(str, "bye"))
break;
len = strlen(str);
cout << k << ". ";
cout << solve(0, 0) << endl;
k++;
}
return 0;
}
Comments
Post a Comment