GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — CompetitiveProgramming/Topcoder/SRM780-D1-1000.cpp at master · danh2006/CompetitiveProgramming Expand file tree/ Copy pathSRM780-D1-1000.cppMore file actions 49 lines (45 loc) · 968 Bytes / Copy pathSRM780-D1-1000.cppFile metadata and controls49 lines (45 loc) · 968 Bytes 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 #include <bits/stdc++.h> using namespace std; #define ll long long const int mxN=1e3, M=1e9+7; int n; ll dp[mxN][8], ndp[8]; vector<int> adj[mxN]; void ad(ll &a, ll b) { a+=b; if(a>=M) a-=M; } class RestrictedLeaves { public: void dfs(int u=0) { if(adj[u].size()) { dfs(adj[u][0]); for(int i=0; i<8; ++i) { ad(dp[u][i&3], dp[adj[u][0]][i]); if(i<4) ad(dp[u][4|i], dp[adj[u][0]][i]); } adj[u].erase(adj[u].begin()); for(int v : adj[u]) { dfs(v); memset(ndp, 0, sizeof(ndp)); for(int i=0; i<8; ++i) for(int j=0; j<8; ++j) if(!(i&4&&j&4)&&!(i&1&&j&2)) ad(ndp[(i&4)|(i&2)|(j&1)], dp[u][i]*dp[v][j]%M); memcpy(dp[u], ndp, sizeof(dp[0])); } } else dp[u][0]=dp[u][7]=1; } int count(vector<int> p) { n=p.size(); for(int i=0; i<n; ++i) adj[i].clear(); for(int i=1; i<n; ++i) adj[p[i]].push_back(i); dfs(); return (dp[0][0]+dp[0][1]+dp[0][2]+dp[0][4]+dp[0][5]+dp[0][6])%M; } }; |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |