您的位置:首页 > 其它

UVA11258

2015-11-02 21:24 225 查看
/*
UVA 11258
题意:
第一行输入T ;接下来 T 行,每行一个字符串,
问怎样分隔这些字符串(分隔出来的数在int范围内) ,加起来的和最大,输出最大和。

*/

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define ll long long
#define INTMAX 2147483647
const int maxn=210;
using namespace std;
ll num[maxn][maxn];
ll dp[maxn];
char str[maxn];
int main()
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%s",str+1);
int l=strlen(str+1);
for(int p=1;p<=11;p++)
{
for(int i=1,j=p;j<=l;i++,j++)
{
ll tmp=0;
for(int k=i;k<=j;k++)
tmp = tmp*10 + (str[k]-48);
if(tmp<=INTMAX)
num[i][j]=tmp;
else num[i][j]=0;
}
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=l;i++)
for(int j=1;j<=11 && j<=i;j++)
dp[i] = max(dp[i],dp[i-j]+num[i-j+1][i]);
cout<<dp[l]<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: