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 ...
随机推荐
- ORA-12520错误解决一则
问题描写叙述: 今天突然发现连接数据库时报错,用pl/sql dev连接数据时,有时能连接上,有时连接时报: ORA-12520: TNS: 监听程序无法找到须要的server类型的可用句柄 通过se ...
- Jedis Client的使用以及序列化
JedisPool pool = new JedisPool(poolConfig, IP, PORT, timeout); public String set(String key,String v ...
- HashMap源码解读(转)
http://www.360doc.com/content/10/1214/22/573136_78188909.shtml 最近朋友推荐的一个很好的工作,又是面了2轮没通过,已经是好几次朋友内推没过 ...
- linux下执行strlwr函数出错:ld returned 1 exit status
执行strlwr函数时报错.源程序例如以下: #include<stdio.h> #include<string.h> void main() { char s[10]={&q ...
- iOS UITableView的Section Footer加入button
郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 在处理UI ...
- Google Earth数据存储、管理、表现及开发机制
Google Earth数据存储.管理.表现及开发机制 一. Google Earth(Map)介绍 1.1 Google Earth介绍 在众多的地理信息服务提供商中,Google是较早 ...
- jQuery插件实战之fullcalendar(日历插件)Demo
jQuery的插件许多,应用的场景也很丰富,今天我这里给大家介绍一款很有用的日历页面开发插件 - fullcalendar,眼下最新版本号是1.5.1,使用这款插件可以高速帮助你高速编程实现基于web ...
- android 图片浏览器 demo
先上效果图,本demo 会逐步完好 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTU2NTczMDE2NjEz/font/5a6L5L2T/fontsi ...
- 三层架构与MVC
三层简介 先说说Web三层架构这个古老话题.地球人都知道web三层架构是指: • >用户接口层(UI Layer) • >业务逻辑层(Bussiness Layer) • >持久化层 ...
- MVC模块化架构
全面解析ASP.NET MVC模块化架构方案 什么叫架构?揭开架构神秘的面纱,无非就是:分层+模块化.任意复杂的架构,你也会发现架构师也就做了这两件事. 本文将会全面的介绍我们团队在模块化设计方面取得 ...