UVA 11258 Solution - String Partition

/*Solved by using Dynamic Programming */


/*
UVA 11258 -String Partition
uva ID; shoaib05
Accepted Time: 0.003
*/

#include<stdio.h>
#include<string.h>

#define MAX 2147483647
int main()
{
long long table[210],sum,val,mul;
char ch[210];
int i,j,k,len,test;
scanf("%d",&test);
while(test--)
{
scanf("%s",ch);
len=strlen(ch);
table[0]=0;
for(i=1;i<=len;i++)
{
table[i]=0;
j=i;
val=0;
mul=1;
while(j>=1)
{
j--;
val=val+(ch[j]-48)*mul;
if(val>MAX)
break;
sum=table[j]+val;
table[i]=table[i]>sum?table[i]:sum;
mul=mul*10;
}
}
printf("%lld\n",table[len]);
}
return 0;
}

Comments

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System