1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <string> #include <sstream> #include <cstdio> #define MAX 100 using namespace std; int main() { int _case; cin >> _case; for( ; _case ; --_case ) { int w,n; (cin >> w >> n).get(); string s; //getline(cin,s); unsigned long long int data[MAX][MAX]; for( int i = 0 ; i<MAX ; ++i ) for( int j = 0 ; j<MAX ; ++j ) data[i][j] = 1; for( int i = 0 ; i<w ; ++i ) { string s; int n; getline(cin,s); istringstream iss(s); iss >> n; while( iss >> n ) data[i][n-1] = 0; } data[0][0] = 1; for( int i = 0 ; i<w ; ++i ) { for( int j = 0 ; j<n ; ++j ) { if( i == 0 || j == 0 ) data[i][j] = 1; else if( data[i][j] != 0 ) { data[i][j] = 0; if( data[i-1][j] != 0 ) data[i][j] += data[i-1][j]; if( data[i][j-1] != 0 ) data[i][j] += data[i][j-1]; } /* TEST */ if(1) { for( int i = 0 ; i<w ; ++i ) { for( int j = 0 ; j<n ; ++j ) printf("% 3d",data[i][j]); cout << endl; } getchar(); } } } cout << data[w-1][n-1] << endl; getchar(); } return 0; } |
Direct link: https://paste.plurk.com/show/303544