uav 11258 String Partition (DP)
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
1234554321
5432112345
000
121212121212
2147483648
11111111111111111111111111111111111111111111111111111
Sample output
543211239
0
2121212124
214748372
5555555666
#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)的更多相关文章
- leetcode_1048. Longest String Chain_[DP,动态规划,记忆化搜索]
1048. Longest String Chain https://leetcode.com/problems/longest-string-chain/ Let's say word1 is a ...
- 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 ...
- HDU4681 String(dp)
题目链接. #include <iostream> #include <cstdio> #include <cstring> #include <cstdli ...
- hdu 4055 Number String(dp)
Problem Description The signature of a permutation is a string that is computed as follows: for each ...
- hdu3336 Count the string kmp+dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 很容易想到用kmp 这里是next数组的应用 定义dp[i]表示以s[i]结尾的前缀的总数 那么 ...
- hdu5707-Combine String(DP)
Problem Description Given three strings a, b and c , your mission is to check whether c is the combi ...
- 10.Regular Expression Matching (String; Back-Track,DP)
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- HDU 4055 Number String (计数DP)
题意:由数字1到n组成的所有排列中,问满足题目所给的n-1个字符的排列有多少个,如果第i字符是‘I’表示排列中的第i-1个数是小于第i个数的. 如果是‘D’,则反之. 析:dp[i][j] 表示前 i ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- 华为C8816电信版ROOT过程
华为C8816电信版ROOT方法, 网上的方法都不太靠谱.. 昨天弄了好久, 最终搞定.. 整理了一下.. 实用到的就方便多了. <方法不再啰嗦, 都有说明> 1. 获取手机解锁passw ...
- CentOS 6.5 配置 SSDB 1.8.0
环境说明: OS:CentOS 6.5 (阿里云ECS) 相关链接: 1.SSDB 下载配置:http://ssdb.io/docs/install.html 2.SSDB 入门文档:http:// ...
- SE 2014年4月30日
如图配置: SW1 SW2 SW3 SW4组成一环型网络 Sw2 和Sw4个存在两业务vlan(vlan 10 和vlan 20) 1.Smart Link 组1 的引用实例1(绑定VLAN 10 ) ...
- C:打印菱形(自己的方法)
//-------------------*打印菱形*--------------------- int i,j,k; int n; printf("请输入一个奇数n:"); sc ...
- Codeforces Jzzhu and Sequences(圆形截面)
# include <stdio.h> int f[10]; int main() { int x,y,n,j; while(~scanf("%d%d%d",& ...
- jquery再体验
$(function(){ var obj = $("div[id^='channel_'][id$='_left']"); var val = obj.html(); var i ...
- hdu 4857 逃生 拓扑排序+PQ,剥层分析
pid=4857">hdu4857 逃生 题目是求拓扑排序,但不是依照字典序最小输出,而是要使较小的数排在最前面. 一開始的错误思路:给每一个点确定一个优先级(该点所能到达的最小的点) ...
- [置顶] Codeforces Round #197 (Div. 2)(完全)
http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...
- Wind River Linux 6 Security Profile
2692407267@qq.com,很多其它内容请关注http://user.qzone.qq.com/2692407267 Wind River Linux 6 Security Profile
- 【设计优化】-使用缓冲(Buffer)提高程序性能
缓冲区是一块特定的内存区域.开辟缓冲区的目的是通过缓解应用程序上下层之间的性能差异,提高系统性能. 缓冲能够协调上层组件和下层组件的性能差异.当上层组件性能因为下层组件时,能够有效地降低上层组件对下层 ...