这题的输入很坑人,和我在蓝桥杯比赛中遇到的一个题一样,每行输入不顾定的字符。这题的转移方程很好找,因为要求时间少,因此对于位置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;
}