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. LDA主题模型学习笔记3.5:变分參数推导

    如今来推导一下得到变分參数更新式的过程.这一部分是在论文的附录中,为避免陷入过多细节而影响总体理解.能够在刚開始学习LDA的时候先不关注求解细节.首先要把L写成关于γ,ϕ\gamma,\phi函数.依 ...

  2. dell N5010

    Inspiron N5010Microsoft Windows 10 企业版 (64位) (英特尔)Intel(R) Core(TM) i3 CPU       M 370  @ 2.40GHz(24 ...

  3. 新版SDK自己主动加入PlaceholderFragment的思考

    自从Android SDK更新到22.6.3,发现新建Activity的时候,会自己主动生成一个Fragment.这个Fragment是activity的静态内部类.同一时候生成了一个xml叫frag ...

  4. Android多线程文件下载器

    本应用实现的是输入文件的网络的地址,点击button開始下载,下载过程中有进度条和后面的文本提示进度, 下载过程中button不可点击,防止反复的下载,完成下载后会进行Toast的提示显示, 而且回复 ...

  5. java获取当前日期时间代码总结

    1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值.  方法如下: 要使用 java.util.Date .获取当前时间的代码如下  代码如下 复制代码 Date date = new ...

  6. Java算法分析1—————寻找数组同样元素

    算法的两个评測指标:执行时间和内存消耗 要么用时间换空间,要么用空间换时间 寻找数组同样元素測试一: 0~99共100个元素各不同样,新增加一个0~99的元素不明白位置 从101个元素数组中找出与0~ ...

  7. 使用 angular directive 和 json 数据 D3 随着标签 donut chart演示样本

    使用angular resource载入中priorityData.json中间json数据,结合D3绘制甜甜圈图.执行index.html其结果见于图.: priorityData.json中jso ...

  8. Uva11464 开关问题

    给一个n×n的01矩阵,你的任务是将尽量少的0变成1,是的每个元素的上下左右的位置(如果存在的话)的之和均为偶数.1<=n<=15. 如果暴力整个矩阵,那么时间复杂度是O(2^(n*n)) ...

  9. Windows Phone开发(36):动画之DoubleAnimation

    原文:Windows Phone开发(36):动画之DoubleAnimation 从本节开始,我们将围绕一个有趣的话题展开讨论--动画. 看到动画一词,你一定想到Flash,毕竟WP应用的一个很重要 ...

  10. Windows Phone开发(33):路径之其它Geometry

    原文:Windows Phone开发(33):路径之其它Geometry 上一节中,我们把最复杂的PathGeometry给干了,生剩下几个家伙就好办事了.一起来见见他们的真面目吧. 一.LineGe ...