Created
March 12, 2015 02:36
-
-
Save jporcelli/57a7e7ecb8bd557d48d3 to your computer and use it in GitHub Desktop.
Uva 910, TV game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define _ ios_base::sync_with_stdio(0);cin.tie(0); | |
using namespace std; | |
#define PI acos(-1) | |
#define sqr(x) ((x) * (x)) | |
#define PB push_back | |
#define MP make_pair | |
#define F first | |
#define S second | |
#define ALL(c) (c).begin(), (c).end() | |
#define SIZE(c) (int)(c).size() | |
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++) | |
#define REPD(i, a, b) for (int i = int(a); i >= int(b); i--) | |
typedef unsigned long long ull; | |
typedef long long ll; | |
typedef pair<int,int> ii; | |
typedef pair<double,double> dd; | |
typedef vector<int> vi; | |
typedef vector<ii> vii; | |
typedef vector<vi> vvi; | |
typedef vector<string> vs; | |
typedef map<int,int> mii; | |
typedef set<int> si; | |
const int MAXN=26, MAXM=30; | |
bool s[MAXN]={false}; | |
vii g; | |
ll dp[MAXN][MAXM+1]={{0}}; //# ways to win from city i, with j moves left to go | |
int m, n; | |
#define PROD //clocking off | |
int main() { | |
#ifndef PROD | |
clock_t stop_s,start_s; | |
start_s=clock(); | |
#endif | |
while(cin >> n) { | |
g.resize(n+1); | |
REP(i, 0, MAXN-1) { s[i]=false; REP(j, 0, MAXM) { dp[i][j]=0; } } | |
char x, y, z, d; | |
REP(i, 1, n) { | |
cin >> x >> y >> z >> d; | |
int v=x-'A'; | |
g[v].F= y-'A'; | |
g[v].S= z-'A'; | |
if(d == 'x') { s[v]=true; } else { s[v]= false; } | |
} | |
cin >> m; | |
REP(i, 0, n-1) { if(s[i]) { dp[i][0]=1; }} | |
REP(i, 1, m) { REP(j, 0, n-1) { | |
dp[j][i] += dp[g[j].F][i-1] + dp[g[j].S][i-1]; | |
}} | |
cout << dp[0][m] << endl; | |
} | |
#ifndef PROD | |
stop_s=clock(); | |
cout << "time: " << (stop_s-start_s)/double(CLOCKS_PER_SEC)*1000 << endl; | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment