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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- Spark入门之DataFrame/DataSet
目录 Part I. Gentle Overview of Big Data and Spark Overview 1.基本架构 2.基本概念 3.例子(可跳过) Spark工具箱 1.Dataset ...
- windows php文件下载地址
http://windows.php.net/downloads/releases/archives/
- D - Vanya and Fence
Problem description Vanya and his friends are walking along the fence of height h and they do not wa ...
- MySQL学习笔记之右连接
MySQL的右连接 #右连接,以右表为基表 select course.stuid,course.stuname,sex,course,city from class1 right join cour ...
- net .异步委托知识
以前在编程中,异步用的比较少,导致C# 一些基础的 东西用法都不怎么熟悉,经常要用的时候在去查找资料比较被动,而已没真正里面理解起来,始终感觉不是自己的知识 (题外话) 首先委托关键字 Delega ...
- Bootstrap3.0的栅格布局系统实现原理
这个标题取的有点奇怪,怪我翻译的有问题吧.英文学平有限,有道词典和google翻译齐上阵是必须的.还好翻译的不是小说,对于技术文章,还是能勉强翻过来的. 本文主要讲解了Bootstrap3.0的栅格布 ...
- Android 复制文本内容到系统剪贴板(自由复制)
直接上代码:(对应的类:android.content.ClipboardManager) //获取剪贴板管理器: ClipboardManager cm = (ClipboardManager) g ...
- 高通处理器手机 解锁Bootloader 教程
目前很多手机都需要解锁Bootloader之后才能进行刷机操作 本篇教程教你如何傻瓜式解锁Bootloader 首先需要在设置-关于手机 找到版本号(个别手机可能是内核版本号,甚至其他) 然后 快 ...
- 【Linux】磁盘分区
我们在Linux操作过程中,可能会遇到磁盘分区的问题.这篇文章是对/dev/sdb 这块磁盘进行分区. linux分区不同于windows,linux下硬盘设备名为(IDE硬盘为hdx(x为从a—d) ...
- dubbo之异步调用
异步调用 基于 NIO 的非阻塞实现并行调用,客户端不需要启动多线程即可完成并行调用多个远程服务,相对多线程开销较小. 在 consumer.xml 中配置: <dubbo:reference ...