poj 1992 jack

Jack

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 2
Problem Description
We need to have at least one computer game in our collection, of course. The typical one could be described as "chase in the town". The smiling face called Jack in our case is walking through the town divided into small fields. Some of the fields are covered with the wall and it is not possible to go through them. Jack collects the points and tries to avoid contact with the monsters who chase him. Once the Jack eats the special point (or asterisk), the situation turns upside-down and Jack can eat monsters. And so on, still again and again. I am sure everyone of you have ever seen such game.  

The town is randomly generated in our case. Jack always starts in the top left corner and the "bonus asterisk" is in the bottom right corner. At the most difficult level, the bonus is set to disappear after exactly as much steps that are sufficient to get from one corner to another, providing Jack only makes steps to the left and to the bottom. Should he made one single step into the wrong direction and he never could be there in time. But it is still important to prevent being catched by monsters. So the player has to choose the best possible way to the bottom right corner. You are to determine how many different ways exist in the town.  
 

Input
The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Each assignment begins with the line containing two possitive numbers R and S (1 <= R,S <= 1000). The numbers determine the number of town rows and columns. Then there are R lines each containing exactly S characters. Each character may be either hash (#) or period (.). Hash mark means the wall and the period is free space. The top left and bottom right corners are always free.
 

Output
Print exactly one line for each of the input cases. The line must contain the statement "Existuje X ruznych cest.", (There are X different paths). Replace X with the number of all existing different paths between the top left and the bottom right corner. Each path must consist of R+S-2 steps, each leading to the left or to the right. No path can cross any field with the wall.
 

Sample Input
  
  
2 3 3 ... .#. ... 1 6 ...#..
 

Sample Output
  
  
Existuje 2 ruznych cest. Existuje 0 ruznych cest.
 显然动归方程f[i][j]=f[i-1][j]+f[i][j-1];
初始条件f[1][1]=1;
注意循环的时候不能再次做(1,1)点
另外cin.getline(map[i]+1,1001)就表示存的时候直接从第一位储存字串
还要注意用getchar()掉字串行前面的回车。
代码如下
#include<iostream>
#include<cstdio>
using namespace std;
char map[1001][1001];
int f[1001][1001],i,j,k,n,m,w;
int main()
{
	char s;
	cin>>k;
	for (w=1;w<=k;w++)
	{
		cin>>n>>m;
		getchar();
		for (i=0;i<=n;i++)
			for (j=0;j<=m;j++)
				f[i][j]=0;
		for(i=1;i<=n;i++)
            cin.getline(map[i]+1,1001);  
		f[1][1]=1;
		for (i=1;i<=n;i++)
			for (j=1;j<=m;j++)
			if (map[i][j]=='.')
			if (i!=1||j!=1)
				f[i][j]=f[i-1][j]+f[i][j-1];
		cout<<"Existuje "<<f[n][m]<<" ruznych cest."<<endl ;
	}
	return 0;
}

		

 
 
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值