UVa 825 - Walking on the Safe Side

这题的输入很坑人,和我在蓝桥杯比赛中遇到的一个题一样,每行输入不顾定的字符。这题的转移方程很好找,因为要求时间少,因此对于位置i, j 只能从左边或者上边走到,

dp[i][j] = dp[i - 1][j] + dp[i][j - 1]



/*************************************************************************
    > File Name: UVa825.cpp
    > Author: Toy
    > Mail: ycsgldy@163.com 
    > Created Time: 2013年05月08日 星期三 21时02分59秒
 ************************************************************************/

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAX = 105;
int Case, row, cul, cnt, dp[MAX][MAX], tmp;
char ch[MAX];
bool opt[MAX][MAX];

int main ( ) {
	cin >> Case;
	while ( Case-- ) {
		cin >> row >> cul;
		getchar ( );

		memset ( opt, 1, sizeof ( opt ) );
		memset ( dp, 0, sizeof ( dp ) );

		for ( int i = 1; i <= row; ++i ) {
			cin >> tmp;
			gets ( ch );
		    int len = strlen ( ch );
			cnt = 0;
			for ( int j = 0; j <= len; ++j ) 
				if ( '0' <= ch[j] && ch[j] <= '9' ) cnt = cnt * 10 + ch[j] - '0';
				else opt[tmp][cnt] = 0, cnt = 0;
		}

		dp[1][1] = 1;
		opt[1][1] = 0;
		for ( int i = 1; i <= row; ++i ) 
			for ( int j = 1; j <= cul; ++j ) 
				if ( opt[i][j] ) dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
		cout << dp[row][cul] << endl;
		if ( Case != 0 ) cout << endl;
	}
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值