poj 1239 Increasing Sequences dp lis
来源:互联网 发布:JAVA绘制窗体 编辑:程序博客网 时间:2024/05/29 11:02
Increasing Sequences
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3081 Accepted: 1174
Description
Given a string of digits, insert commas to create a sequence of strictly increasing numbers so as to minimize the magnitude of the last number. For this problem, leading zeros are allowed in front of a number.
Input
Input will consist of multiple test cases. Each case will consist of one line, containing a string of digits of maximum length 80. A line consisting of a single 0 terminates input.
Output
For each instance, output the comma separated strictly increasing sequence, with no spaces between commas or numbers. If there are several such sequences, pick the one which has the largest first value;if there's a tie, the largest second number, etc.
Sample Input
34563546352600011000001010
Sample Output
3,4,5,635,463,5,260001100,000101
Source
East Central North America 2002
[Submit] [Go Back] [Status] [Discuss]
求把一个数划分若干个数然后要满足构成数是递增的 在保证最后一个数最小的情况下第一个数最大
ACcode
#include <iostream>#include <cstdio>#include <cstring>#define maxn 100using namespace std;int dp[maxn];char str[maxn];bool big(int i,int j,int m,int n){ while(str[i]=='0'&&i<=j)i++; while(str[m]=='0'&&m<=n)m++; if(i>j)return false; if(m>n)return true; int a=j-i+1,b=n-m+1; if(a>b)return true; if(a<b)return false; for(int t=i,p=m;t<=j&&p<=n;++p,++t) if(str[t]>str[p])return true; else if(str[t]<str[p])return false; return false;}int main(){ while(scanf("%s",str+1)!=EOF){ int len=strlen(str+1); if(len==1&&str[1]=='0')break; for(int i=1;i<=len;++i)dp[i]=i; for(int i=2;i<=len;++i) for(int j=i-1;j>0;--j) if(big(j+1,i,j-dp[j]+1,j)){ dp[i]=i-j; break; } int pos=len-dp[len]+1; dp[pos]=dp[len]; for(int i=pos-1;i>0;--i){ if(str[i]=='0'){ dp[i]=dp[i+1]+1; continue; } for(int j=pos;j>i;--j) if(big(j,j+dp[j]-1,i,j-1)){ dp[i]=j-i; break; } } // for(int i=1;i<=len;++i)cout<<dp[i]<<' '; //cout<<'\12'; for(int i=1;i<=dp[1];++i)putchar(str[i]); pos=dp[1]+1; while(pos<=len){ putchar(','); for(int i=pos;i<dp[pos]+pos;++i)putchar(str[i]); pos=pos+dp[pos]; } putchar('\n'); } return 0;}
0 0
- poj 1239 Increasing Sequences dp lis
- Increasing Sequences - POJ 1239 dp
- POJ 1239-Increasing Sequences(LIS 分割成上升序列-两次DP)
- 两次dp-poj-1239-Increasing Sequences
- poj 1239 dp(拆分成Increasing Sequences )
- poj 1239 Increasing Sequences
- POJ 1239 Increasing Sequences 笔记
- POJ 题目1239 ||ZOJ 题目 1499 Increasing Sequences(正反两次DP)
- 1239 Increasing Sequences
- DP-LIS( Longest Increasing Subsequenc)
- Longest increasing substring (LIS)--DP
- Increasing Sequences-ZOJ 1499 POJ 1039
- DP中的LIS:longest increasing subsequence
- poj 2533 DP(LIS)
- poj 1836 dp lis
- POJ 3670 DP LIS?
- poj-3616 DP,LIS
- [DP-LIS] POJ 2533
- Dubbo高级篇_10_Dubbo消费端直连服务提供者(开发调试)
- 安卓开发 第二篇 我的安卓应用架构设计
- 年月日计算
- activiti实战系列 并行网关(parallelGateWay)
- 2016.4.16 随想
- poj 1239 Increasing Sequences dp lis
- C# Socket多线程编程实例-聊天程序
- 通过下标全选反选,删除
- 用C语言创建文件写入并读取
- toncat报错-->'Start Tomcat v8.0 Server at localhost' has encountered a problem.
- NDCG Normalized discounted cumulative gain 理解分析
- 【笔试/面试】—— 不使用大于、小于、if 语句,实现 max 宏
- 智能进化论
- C++删除元素的函数总结