OJ题号:ZHOJ1297

思路:搜索。

先预处理注定不能走的路径,然后dfs可以走的路径。

 #pragma GCC optimize ("O2")
#include<cstdio>
#include<cstdlib>
#include<cctype>
const int N=;
int n,m,len,a[N][N]={{}},path[N<<];
int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
void printpath() {
for(int i=;i<len;i++) printf("%d ",path[i]);
puts("");
}
void dfs(int x,int y) {
if(!a[x][y]) return;
path[x+y]=a[x][y];
if((x+y+)==len) {
printpath();
exit();
}
if((x+)==n) {
dfs(x,y+);
return;
}
if((y+)==m) {
dfs(x+,y);
return;
}
if(a[x+][y]<a[x][y+]) {
dfs(x+,y);
dfs(x,y+);
}
else {
dfs(x,y+);
dfs(x+,y);
}
}
int main() {
n=getint();
m=getint();
len=n+m-;
for(register int i=;i<n;i++) {
for(register int j=;j<m;j++) {
a[i][j]=getint();
}
}
for(register int i=n-;i>=;i--) {
for(register int j=m-;j>=;j--) {
if((i==(n-))&&(j==(m-))) continue;
if(!a[i+][j]&&!a[i][j+]) a[i][j]=;
}
}
if(a[n-][m-]) dfs(,);
puts("Oh,the life is too difficult!");
return ;
}

【NOIP2014模拟赛No.1】我要的幸福的更多相关文章

  1. 2014-9-13 NOIP模拟赛

    NOIP2014模拟赛 ——lwher 题目名 环上的游戏 舞蹈课 数位和乘积 源文件 cycle.cpp/c/pas dancingLessons.pas/cpp digit.cpp.cpp/c/p ...

  2. 2014-10-23 NOIP模拟赛

    NOIP2014模拟赛 -----lwher 时限均为1s,内存 256MB 1.Jams倒酒(pour) Jams是一家酒吧的老板,他的酒吧提供2种体积的啤酒,a ml 和 b ml,分别使用容积为 ...

  3. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  4. NOI模拟赛 Day1

    [考完试不想说话系列] 他们都会做呢QAQ 我毛线也不会呢QAQ 悲伤ING 考试问题: 1.感觉不是很清醒,有点困╯﹏╰ 2.为啥总不按照计划来!!! 3.脑洞在哪里 4.把模拟赛当作真正的比赛,紧 ...

  5. NOIP第7场模拟赛题解

    NOIP模拟赛第7场题解: 题解见:http://www.cqoi.net:2012/JudgeOnline/problemset.php?page=13 题号为2221-2224. 1.car 边界 ...

  6. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  7. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  8. 小奇模拟赛9.13 by hzwer

    2015年9月13日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿(explo) [题目背景] 小奇要开采一些矿物,它驾驶着一台带有钻头(初始能力值w)的飞船,按既定路线依次飞 ...

  9. PKUSC 模拟赛 day1 下午总结

    下午到了机房之后又困又饿,还要被强行摁着看英文题,简直差评 第一题是NOIP模拟赛的原题,随便模拟就好啦 本人模拟功力太渣不小心打错了个变量,居然调了40多分钟QAQ #include<cstd ...

随机推荐

  1. sqlserver2008r2数据库关联孤立账号的方法

    重新安装mssql数据库后可能有这样的问题,     在数据还原到其他服务器时,登录名会丢失,重建非常麻烦     特別是数据库用户较多的的情况,其实这个问题解决非常简单,     sql serve ...

  2. (转)eclipse 创建maven web项目

    1.新建Maven项目 1.1 File -> New -> Other 1.2 选择Maven Project ,单击Next 1.3 保持默认即可,单击Next 1.4 选择Arche ...

  3. Python-JS事件与面向对象操作

    目录一.函数高级 循环绑定: 使用循环绑定会出现的问题及解决方案: 二.面向对象 3.构造函数(ES5) 三.JS选择器 1.getElement系列(最严谨) 2.querySelector系列(最 ...

  4. PYTHON-文件处理-练习

    ## 一.实现用户注册功能# 思路:# 用户输入用户名.密码# 将用户输入的内容按照固定的格式,比如:egon:123,存入文件# 可以往一个文件中重复注册新的用户名和密码# 附加:# 1.对输入的用 ...

  5. winform(记事本--保存和退出)

  6. [主席树 强制在线]ZOJ3888 Twelves Monkeys

    题意:有n年,其中m年可以乘时光机回到过去,q个询问 下面m行,x,y 表示可以在y年穿越回x年, 保证y>x 下面q个询问, 每个询问有个年份k 问的是k年前面 有多少年可以通过一种以上($\ ...

  7. poj3468

    #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define ...

  8. 有关Math数学运算的js函数

    随机函数;  Moth.random()   //3.以下通过循环给数组每个元素赋值,随机数. // Math.random(); 可以随机0~1之间的任意数 [0,1) // alert(Math. ...

  9. 注解工具ButterKnife用法和注意点

    // implementation 'com.android.support:appcompat-v7:28.0.0-Beta1' // implementation 'com.android.sup ...

  10. ahoi2009维护序列

    链接:https://www.luogu.org/problemnew/show/P2023 裸的线段树维护+* 代码: #include <bits/stdc++.h> using na ...