Submission #371866

#TimeUsernameProblemLanguageResultExecution timeMemory
371866Andyvanh1Calvinball championship (CEOI15_teams)C++14
10 / 100
58 ms65540 KiB
#include <iostream> #include <algorithm> #include <vector> #include <stack> using namespace std; #define vt vector #define INF INT_MAX #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef vt<pair<int,int>> vpii; vt<vi> adjlist; vt<bool> visited; void solve(){ int n, r; cin>>n>>r; adjlist.resize(n); for(int i = 0; i < r; i++){ int u, v; cin>>u>>v; adjlist[u-1].pb(v-1); adjlist[v-1].pb(u-1); } int sz = (1<<n); bool bol1 = false; for(int j = 1; j < sz; j++){ bool arr[n]; for(int i = 0; i < n; i++){ arr[i] = false; } int jj = j; int idn = 0; while(jj!=0){ if(jj%2==1){ arr[idn] = true; } jj/=2; idn++; } vi a; for(int i = 0; i < n; i++){ if(arr[i]){ a.pb(i); } } if(a.size()<=3){ continue; } bool bol = true; for(auto& e:a){ int ct = 0; for(auto& ee: adjlist[e]){ if(arr[ee]){ ct++; } } if(ct!=2){ bol = false; break; } } if(bol){ visited.resize(n); for(int i = 0; i < n; i++){ visited[i] = false; } vi b; stack<int> stk; stk.push(a[0]); visited[a[0]] = true; while(!stk.empty()){ int node = stk.top(); stk.pop(); b.pb(node); for(auto&e : adjlist[node]){ if(arr[e]&&!visited[e]){ stk.push(e); visited[e] = true; } } } for(auto& e: b){ cout<<e+1<<" "; } bol1 = true; break; } } if(!bol1){ cout<<"no"; } } void solve2(){ int n; cin>>n; ll dp[n+1][n+1]; dp[0][0] = 1; for(int i = 1; i <= n; i++){ dp[i][0] = 0; dp[0][i] = 0; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ if(j==i){ dp[i][j] = 1; }else { dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * (ll)j; } dp[i][j]%= 1000007; } } ll ans = 0; for(int i = 1; i<= n; i++){ ans+=dp[n][i]; ans%=1000007; } cout<<ans; } int main() { solve2(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...