男神的约会

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.uestc.edu.cn/#/contest/show/65

Description

有一天男神约了学姐姐去看电影,电影院有一个活动,给你一个10*10的矩阵,每一个格子上都有一个0-9的整数,表示一共十种优惠券中的一种。

观众从左上角的格子开始走,走到右下角。每走到一个有着a号优惠券的格子,都必须要玩一个a分钟的游戏来领取这张优惠券。

每次只能向右或向下走。当走到右下角的时候,如果集齐10种优惠券就可以半价看电影呢。

为了能在学姐姐面前展示自己的才智,男神准备用最少的时间领取全部的优惠券(他要省出最多的时间陪学姐姐)。聪明的你能告诉男神,他最少要花费的时间是多少?

wij 千 克的蛋糕,Gorwin从左上角(1,1)的格子开始走,走到右下角(n,m)的格子。在每一步中,Gorwin可以向右或者向下走,即是:Gorwin 站在(i,j)的时候,她可以走向(i+1,j)或者(i,j+1) (然而她不能走出这个花园)。 当Gorwin到达一个格子的时候,她可以把那个格子里面的蛋糕吃完或者不吃。但是,她不能只吃一部分。她的胃不是那么大,所以她最多只能吃K千克的蛋 糕。现在,Gorwin站在左上角,她在看蛋糕园的地图,想要找出一条路,能够使得她吃到的蛋糕最多的一条路。请你来帮帮忙。

Input

输入包含10行,每行10个数字,以空格隔开,表示格子上的优惠券的种类。数据保证存在合法路径。

Output

输出男神走到右下角的最小时间花费。

Sample Input

0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 0 2 1 1 1 1 1 1 1 1 0 3 1 1 1 1 1 1 1 1 0 4 1 1 1 1 1 1 1 1 0 5 1 1 1 1 1 1 1 1 0 6 1 1 1 1 1 1 1 1 0 7 1 1 1 1 1 1 1 1 0 8 1 1 1 1 1 1 1 1 0 9 1 1 1 1 1 1 1 1 5

Sample Output

50

HINT

题意

题解:

把这道题当成bfs做,在自己的struct里面,记录自己拿卷的情况

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <ctime>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** struct node
{
int x,y;
int v[];
int step;
int ans;
};
int g[][];
queue<node>q;
int dx[]={,};
int dy[]={,};
int main()
{
int n=,m=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
g[i][j]=read();
node now;
memset(now.v,,sizeof(now.v));
now.x=,now.y=;
now.step=g[][];
now.v[g[][]]=;
now.ans=;
q.push(now);
int ans=inf;
while(!q.empty())
{
now=q.front(); q.pop();
if(now.x==&&now.y==&&now.ans==)
{ int flag=;
ans=min(ans,now.step);
continue;
}
for(int i=;i<;i++)
{
node next=now;
next.x+=dx[i];
next.y+=dy[i];
if(next.x<||next.y<||next.y>||next.x>)
continue;
int p=g[next.x][next.y];
next.step+=p;
if(!next.v[p])
{
next.v[p]=;
next.ans++;
}
q.push(next);
}
}
cout<<ans<<endl;
}

UESTC 2015dp专题 j 男神的约会 bfs的更多相关文章

  1. UESTC 2015dp专题 A 男神的礼物 区间dp

    男神的礼物 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descri ...

  2. [dp][uestc oj]J - 男神的约会

    J - 男神的约会 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit ...

  3. UESTC_男神的约会 2015 UESTC Training for Dynamic Programming<Problem J>

    J - 男神的约会 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit ...

  4. 男神的约会(状压dp)

    有一天男神约了学姐姐去看电影,电影院有一个活动,给你一个10*10的矩阵,每一个格子上都有一个0-9的整数,表示一共十种优惠券中的一种. 观众从左上角的格子开始走,走到右下角.每走到一个有着a号优惠券 ...

  5. UESTC 2015dp专题 H 邱老师选妹子 数位dp

    邱老师选妹子 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  6. UESTC 2015dp专题 F 邱老师看电影 概率dp

    邱老师看电影 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  7. UESTC 2015dp专题 N 导弹拦截 dp

    导弹拦截 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descrip ...

  8. UESTC 2015dp专题 G 邱老师玩游戏 背包dp

    邱老师玩游戏 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  9. UESTC 2015dp专题 E 菲波拉契数制 dp

    菲波拉契数制 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

随机推荐

  1. apache2启动失败(Failed to start The Apache HTTP Server.)解决方案

    不知道如何启动apache2就启动不来了. 如下图所示: 即使卸载了重新装也是如此 经过测试卸载并清除软件包的配置即可解决 sudo apt-get purge apache2  sudo apt-g ...

  2. windows下制作debian U盘启动

    制作平台:Windows 7 制作debian版本:debian 7.4 wheezy 1.下载引导镜像,包含三个文件:boot.img.gz(解压备用).initrd.gz 和 vmlinuz. h ...

  3. Linux中查看CPU信息 (转)

    cat /proc/cpuinfo中的信息 processor       逻辑处理器的id. physical id    物理封装的处理器的id. core id        每个核心的id. ...

  4. rcnn ->fast rcnn->faster rcnn物体检测论文

    faster rcnn中的rpn网络: 特征可以看做一个尺度51*39的256通道图像,对于该图像的每一个位置,考虑9个可能的候选窗口:三种面积{1282,2562,5122}×三种比例{1:1,1: ...

  5. 【转载】Beautiful Soup库(bs4)入门

    转载自:Beautiful Soup库(bs4)入门 该库能够解析HTML和XML 使用Beautiful Soup库:      from bs4 import BeautifulSoup impo ...

  6. hdu 5468(dfs序+容斥原理)

    Puzzled Elena Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. Python 3.6安装教程

    0x01 安装Python 1.1 说明 目前,Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. 本教程安装的是python-3.6.1-amd64版本. Python官 ...

  8. Jmeter-----保存到响应文件

    在jmeter中使用保存响应到文件 ------适用于非GUI模式执行脚本时,无法查看报错的信息. 1.添加组件: 2.各个配置项说明: 1.名称:即组件在整个测试计划中的名称显示,建议设置为用意义的 ...

  9. [你必须知道的.NET]第二十回:学习方法论

    说在,开篇之前 本文,源自我回答刚毕业朋友关于.NET学习疑惑的回复邮件. 本文,其实早计划在<你必须知道的.NET>写作之初的后记部分,但是因为个中原因未能如愿,算是补上本书的遗憾之一. ...

  10. tensorflow运行出现错误 : ImportError: Could not find 'cudart64_90.dll'.

    安装 tensorflow-gpu 版本后,需要安装相应的 CUDA 和 cuDNN 注意版本问题:tensorflow-gpu 1.7以及之后的版本要安装 CUDA 8.0 以上的版本,tf 1.7 ...