Problem F - String Partition
                                                                                                                   
Time limit: 3.000 seconds



John was absurdly busy for preparing a programming contest recently. He wanted to create a ridiculously easy problem for the contest. His problem was not only easy, but also boring: Given a list of non-negative integers, what is the sum of them?

However, he made a very typical mistake when he wrote a program to generate the input data for his problem. He forgot to print out spaces to separate the list of integers. John quickly realized his mistake after looking at the generated input
file because each line is simply a string of digits instead of a list of integers.



He then got a better idea to make his problem a little more interesting: There are many ways to split a string of digits into a list of non-zero-leading (0 itself is allowed) 32-bit signed integers.
What is the maximum sum of the resultant integers if the string is split appropriately?



Input

The input begins with an integer N (≤ 500) which indicates the number of test cases followed. Each of the following test
cases consists of a string of at most 200 digits.



Output

For each input, print out required answer in a single line.



Sample input

6

1234554321

5432112345

000

121212121212

2147483648

11111111111111111111111111111111111111111111111111111

Sample output

1234554321

543211239

0

2121212124

214748372

5555555666
 
 
题意:给定一个字符串序列。让你把它划分成几个int型的数字,而且使这些数字之和最大。

 
思路:dp[i]表示前i个字符划分时的和的最大值。
dp[i] = max(dp[i], dp[i-j]+num),num为从后往前划分为j长度的数字。

 
 
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <climits>
#define LL long long
using namespace std;
const LL inf=INT_MAX;
const int maxn=210; LL dp[maxn];
string str; void initial()
{
memset(dp,0,sizeof(dp));
} void input()
{
cin>>str;
} int get_num(char ch)
{
return ch-'0';
} void solve()
{
int len=str.size();
dp[1]=get_num(str[0]); for(int i=2;i<=len;i++)
{
LL tmp=1,now=0;
for(int k=i-1,j=1;k>=0;k--,j++)
{
now=get_num(str[k])*tmp+now;
if(now>inf) break;
dp[i]=max(dp[i],dp[i-j]+now);
tmp*=10;
}
}
printf("%lld\n",dp[len]);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
initial();
input();
solve();
}
return 0;
}

uav 11258 String Partition (DP)的更多相关文章

  1. leetcode_1048. Longest String Chain_[DP,动态规划,记忆化搜索]

    1048. Longest String Chain https://leetcode.com/problems/longest-string-chain/ Let's say word1 is a ...

  2. hdu 3336 Count the string KMP+DP优化

    Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...

  3. HDU4681 String(dp)

    题目链接. #include <iostream> #include <cstdio> #include <cstring> #include <cstdli ...

  4. hdu 4055 Number String(dp)

    Problem Description The signature of a permutation is a string that is computed as follows: for each ...

  5. hdu3336 Count the string kmp+dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 很容易想到用kmp 这里是next数组的应用 定义dp[i]表示以s[i]结尾的前缀的总数 那么 ...

  6. hdu5707-Combine String(DP)

    Problem Description Given three strings a, b and c , your mission is to check whether c is the combi ...

  7. 10.Regular Expression Matching (String; Back-Track,DP)

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  8. HDU 4055 Number String (计数DP)

    题意:由数字1到n组成的所有排列中,问满足题目所给的n-1个字符的排列有多少个,如果第i字符是‘I’表示排列中的第i-1个数是小于第i个数的. 如果是‘D’,则反之. 析:dp[i][j] 表示前 i ...

  9. hdu 4055 Number String (基础dp)

    Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. hdu3966(树链剖分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意:一颗树上,每个点有权值,定义三种操作: 1)I操作表示从a到b节点之间的节点都加上一个值 ...

  2. linux--档案权限与目录配置

    下面是最近学习档案权限与目录配置的一些知识点总结***博客园-邦邦酱好*** Linux最优秀的地方之一,就在于他的多人多任务环境.而为了让各个使用者具有较保密的档案数据,因此档案的权限管理就变的很重 ...

  3. 源代码编译安装 PHP5.5.0,解决curl_exec訪问HTTPS返回502错误的问题

    近期碰到一个奇怪的问题. PHP使用 curl_exec 訪问 HTTPS 网页时, 返回502错误, 訪问HTTP网页时没有问题,  用   echo   phpinfo() ;  查看. 支持op ...

  4. 第五章_JSTL

    5.1.下载JSTL http://jstl.java.net 5.2.JSTL类库 类别 下属功能 URI 前缀 Core 变量支持 http://java.sun.com/jsp/jstl/cor ...

  5. 解决vmware卡的要死

    如题: 一般而言虚拟机不会卡的.CPU跟随你的操作而增减,内存设置vmware的推荐值就好.遇到卡的情况,检查一下如下情况. 两个方法: 1>内存分配最好是1G,512少了点 2>虚拟机的 ...

  6. 二十7天 春雨滋润着无形 —Spring依赖注入

    6月11日,明确."夏条绿已密,朱萼缀明鲜.炎炎日正午,灼灼火俱燃." IT人习惯把详细的事物加工成的形状一致的类.正是这种一致,加上合适的规范.才干彰显对象筋道的牙感和bean清 ...

  7. ArcGIS SDE 10.1 for Postgresql 服务连接配置

    去年写了ArcGIS 10.1 如何连接Postgresql 数据库(http://blog.csdn.net/arcgis_all/article/details/8202709)当时采用的也是Ar ...

  8. REDGATE又一好用的脚本工具ScriptsManager1.3

    原文:REDGATE又一好用的脚本工具ScriptsManager1.3 REDGATE又一好用的脚本工具ScriptsManager1.3 先说明一下:这个工具是免费的 下载地址:http://ww ...

  9. wireshark教程

    Wireshark世界上最流行的网络分析工具. 这个强大的工具能够捕捉网络中的数据,并为用户提供关于网络和上层协议的各种信息.与非常多其它网络工具一样.Wireshark也使用pcap network ...

  10. 【buildroot-2011.11】You may have to install &#39;g++&#39; on your build machine

    buildroot - 2011.11 当进行交叉编译.例如像以下错误提及演示: "You may have to install 'g++' on your build machine&q ...