简单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的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. 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 ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. bzoj2115

    线性基+dfs树 我们先搞出dfs树,其实最终路径就是最初的路径和一些环异或. 环最多只有m-n+1,因为一共有m条边,然后有n-1条边在dfs树上,所以还剩m-n+1条边,都可以构成环. 所以dfs ...

  2. PCB .NET连接MySQL与Oracle DLL文分享件 MySql.Data,Oracle.ManagedDataAccess

    虽然我们C#对SQL SERVER天然的支持,但对于C#要连接MYSQL或Oracle就不同了, 需要用到第3方组件才行,本文将2个组件连接数据库代码与DLL下载地址贴出. 一.C#连接MYSQL   ...

  3. python3+request接口自动化框架中自动发送邮件

    在上一篇中的自动化框架中没有放上自动发送测试结果到邮箱的功能,在这篇文章中在补一下,哈哈 1.上一篇的代码就不在一一介绍了,本篇只介绍发送邮件的功能代码 2.在public common 文件夹中创建 ...

  4. 【Codeforces】Codeforces Round #373 (Div. 2) -C

    C. Efim and Strange Grade Efim just received his grade for the last test. He studies in a special sc ...

  5. 多文件上传ajax jquery

    jquery的ajaxSubmit()和多文件上传 <%@ page language="java" import="java.util.*" pageE ...

  6. REST、RESTful、SOA

    1.http://www.imooc.com/article/17650 2.SOA面向服务架构

  7. hibernate_05_单表操作_对象类型

    本篇使用hibernate输出一个对象(图片) 先写一个java类 package com.imooc.hibernate; import java.sql.Blob; import java.uti ...

  8. 团体程序设计天梯赛-练习集-L1-036. A乘以B

    L1-036. A乘以B 看我没骗你吧 —— 这是一道你可以在10秒内完成的题:给定两个绝对值不超过100的整数A和B,输出A乘以B的值. 输入格式: 输入在第一行给出两个整数A和B(-100 < ...

  9. 深入了解Spring Boot 核心注解原理

    SpringBoot目前是如火如荼,所以今天就跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到 ...

  10. [转载]windows下github 出现Permission denied (publickey).解决方法

      今天在学习github的时候遇到了一些问题,然后爬了一会,找到了解决方法记录下来,以防忘记,当然能帮助别人最好啦! github教科书传送门:http://www.liaoxuefeng.com/ ...