poj 1239 Increasing Sequences
来源:互联网 发布:p.cn云计算门户 编辑:程序博客网 时间:2024/05/15 05:38
题目链接:http://poj.org/problem?id=1239
题目大意:求使最后一个数最大且前面的数尽量大的加逗号方式,两次dp,先从前到后求得最后一个数,然后反向dp,求出满足条件且当前数最大的方案。需要注意的是最后一段可加0.
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<string>#include<queue>#include<algorithm>#include<vector>#include<stack>#include<list>#include<iostream>#include<map>using namespace std;#define inf 0x3f3f3f3f#define Max 110int max(int a,int b){return a>b?a:b;}int min(int a,int b){return a<b?a:b;}int dp[100];char str[100];char s1,s2;int len;bool cmp(int st1,int ed1 ,int st2,int ed2){ int i,j; //int tmp; for(i=st1;str[i]=='0'&&i<ed2;i++){} st1=i; for(i=st2;str[i]=='0'&&i<ed2;i++){} st2=i; if(ed1-st1<ed2-st2) return true; else if(ed1-st1>ed2-st2) return false; for(i=0;i+st1<=ed1;i++) { if(str[i+st1]<str[i+st2]) return true; else if(str[i+st1]>str[i+st2]) return false; } return false;}int main(){ int i,j; while(scanf("%s",str)!=EOF) { len=strlen(str); if(str[0]=='0'&&len==1) break; dp[0]=0; for(i=1;i<len;i++) { //dp[i]=i; dp[i]=0; for(j=i-1;j>=0;j--) { if(cmp(dp[j],j,j+1,i)) { dp[i]=j+1; // printf("i %d dp %d\n",i,dp[i]); break; } } } int last=dp[len-1]; dp[last]=len-1; for(i=last-1;i>=0;i--) { dp[i]=-1; if(str[i]=='0') { dp[i]=dp[i+1]; continue; } for(j=last;j>=i+1;j--) { if(cmp(i,j-1,j,dp[j])) { dp[i]=j-1; // printf("i %d %d\n",i,dp[i]); break; } } } int tmp=dp[0]; i=0; while(1) { while(i<=tmp) { printf("%c",str[i]); i++; } if(tmp==len-1) break; printf(","); tmp=dp[tmp+1]; } puts(""); }}
- poj 1239 Increasing Sequences
- Increasing Sequences - POJ 1239 dp
- POJ 1239 Increasing Sequences 笔记
- 两次dp-poj-1239-Increasing Sequences
- poj 1239 dp(拆分成Increasing Sequences )
- poj 1239 Increasing Sequences dp lis
- 1239 Increasing Sequences
- Increasing Sequences-ZOJ 1499 POJ 1039
- POJ 题目1239 ||ZOJ 题目 1499 Increasing Sequences(正反两次DP)
- POJ 1239-Increasing Sequences(LIS 分割成上升序列-两次DP)
- hdu Increasing Sequences
- zoj 1499 Increasing Sequences
- pku1239 Increasing Sequences (动态规划)
- ZOJ1499 POJ1239 HDU1511 Increasing Sequences
- zju 1499 Increasing Sequences(分步动态规划)
- POJ 2034 Anti-prime Sequences
- poj 1432 Decoding Morse Sequences
- poj 2034 Anti-prime Sequences
- Box2D v2.0.1 用户手册
- 文件处理类FileUtil
- 设计模式之责任链
- Ibatis的分页
- 使用 Power Designer 设计数据库并生成脚本
- poj 1239 Increasing Sequences
- IPHONE手机知识大全(上)
- 学习
- ip处理工具类IPUtil
- 老鸟对菜鸟的一些建议
- 软件项目管理的十大定律
- java中memcached基本使用方法
- VC++编译选项
- exercises 2-4