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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- leetcode二分查找相关
目录 33/81搜索旋转排序数组 34在排序数组中查找元素的第一个和最后一个位置 35搜索插入位置 74搜索二维矩阵 300最长上升子序列,354俄罗斯套娃信封问题 33/81搜索旋转排序数组 假设按 ...
- 联想Thinkpad L460安装Win7 64位
单位发了L460,自带的系统为win10,但是涉及到很多工作以及客户都是在win7环境下,所以必须安装win7的系统,经过一番折腾,终于装好了. 主要顺序如下: 1,制作WINPE启动盘,如大白菜,老 ...
- Pet(dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=4707 题意:判断距离大于D的点有多少个. 思路: 邻接表建图,dfs每一个点,记录步数. #include &l ...
- java joor 实现反射简单调用
有时候需要用反射实现代码.直接用工具,joor 上代码: package com.ming.joor; import static org.joor.Reflect.*; public class T ...
- 自己整理的HTML基本标签参考知识
基 本 标 签 创建一个HTML文档 <html></html> 设置文档标题以及其他不在WEB网页上显示的信息 <head></head> ...
- Android截图截取弹框AlertDialog
1:效果如图 2:权限 <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21" ...
- 【sqli-labs】 less22 Cookie Injection- Error Based- Double Quotes - string (基于错误的双引号字符型Cookie注入)
注入的过程和less 20 21一样,这次闭合cookie的使用的双引号
- openstack--memecache
一.缓存系统 静态web页面: 1.工作流程: 在静态Web程序中,客户端使用Web浏览器(IE.FireFox等)经过网络(Network)连接到服务器上,使用HTTP协议发起一个请求(Reques ...
- Mysql 设置起始值
alter table t_tszj_pet_activity AUTO_INCREMENT=10000; 设置 id 从10000 开始
- eas之动态刷新Table
如何刷新表体数据行(表头不变) 示例1:删除所有表体行,并重新发取数事件该方法不会修改原先的绑定信息table.removeRows(); 示例2:删除所有表体行,修改绑定信息并重新取数指定新的que ...