POJ 2030
简单DP题。
可以用运算符重载来写,简单一些。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
using namespace std; class STRS{
public:
char str[100];
void operator=(STRS b){
strcpy(str,b.str);
}
STRS operator+(char b){
STRS tmp;
strcpy(tmp.str,str);
int leng=strlen(tmp.str);
if(tmp.str[0]=='0'){
tmp.str[0]=b;
tmp.str[1]='\0';
}
else{
tmp.str[leng]=b;
tmp.str[leng+1]='\0';
}
return tmp;
}
bool operator >(STRS b){
int al=strlen(str); int bl=strlen(b.str);
if(al>bl) return true;
else if(bl>al) return false;
for(int i=0;i<al;i++){
if(str[i]>b.str[i])
return true;
else if(str[i]<b.str[i])
return false;
}
return false;
}
void initial(){
strcpy(str,"0");
}
}; STRS gp[100],dp[100][100],answer;
int n,m; int main(){
STRS tmpt;
while(scanf("%d%d",&m,&n)!=EOF){
if(n==0&m==0) break;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
dp[i][j].initial();
answer.initial();
for(int i=1;i<=n;i++)
scanf("%s",gp[i].str+1);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(gp[i].str[j]>='0'&&gp[i].str[j]<='9'){
dp[i][j]=dp[i][j]+gp[i].str[j];
tmpt=dp[i][j-1]+gp[i].str[j];
if(tmpt>dp[i][j])
dp[i][j]=tmpt;
tmpt=dp[i-1][j]+gp[i].str[j];
if(tmpt>dp[i][j])
dp[i][j]=tmpt;
if(dp[i][j]>answer)
answer=dp[i][j];
}
}
}
printf("%s\n",answer.str);
}
return 0;
}
POJ 2030的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- php的self和this
<?phpclass ss{ public static $code; public function __construct( $code ) { self::$code=$code; //这 ...
- Elasticsearch 7.1.1 集群 + 配置身份验证
一.安装Elasticsearch 1.1 环境说明 Centos7.6 Elasticsearch7.1.1 #挂载数据盘 fdisk /dev/vdb n,p,,回车,回车,wq fdisk -l ...
- 我的MYSQL学习心得(推荐)
http://www.cnblogs.com/lyhabc/category/573945.html
- 简单的UIButton按钮动画效果iOS源码
这个是简单的UIButton按钮动画效果案例,源码,简单的UIButton按钮动画,可以自定义button属性. 效果图: <ignore_js_op> 使用方法: 使用时把ButtonA ...
- svn命令行批量删除和批量添加
svn命令行批量删除和批量添加 如果使用svn的命令行,例如在linux下的终端中使用,svn的添加命令是svn add,删除命令是svn del,但是缺乏批量的操作,如果我在资源管理器中,手动添加了 ...
- 红黑联盟 php相关资讯
http://www.2cto.com/tag/phpbanben.html
- [Intermediate Algorithm] - Binary Agents
题目 传入二进制字符串,翻译成英语句子并返回. 二进制字符串是以空格分隔的. 提示 String.charCodeAt() String.fromCharCode() 测试用例 binaryAgent ...
- BRAFT EDITOR富文本编辑器
https://braft.margox.cn/demos/basic 官方文档 import React from 'react' import Uploading from '../Upl ...
- :before和:after结合使用
<div class="slider-block" id="block" style="left: 15.5px;" data=&qu ...
- Apex语言(六)数组
1.数组 数组能保存多个数据,每一个数据称为数组元素,元素的个数称为数组的长度. 数组元素的类型必须相同,元素的类型就是数组的类型. 数组元素在数组中都有一个编号,称为数组下标.下标从0开始编号,通过 ...