Submission #118396

#TimeUsernameProblemLanguageResultExecution timeMemory
118396silxikysCalvinball championship (CEOI15_teams)C++14
0 / 100
52 ms8500 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e4+4, M = 1e9+7; int n, a[maxn]; void madd(int& a, int b) { a = (a+b) % M; } int mult(int a, int b) { return (1LL*a*b) % M; } /* * f(i,j) = # combinations, w/ i spaces left, that can be up to j * f(i,j) = j*f(i-1,j) + f(i-1,j+1) * f(1,x) = x * f(2,x) = j*x+x+1 = (j+1)*x+1 * * */ int dp[1003][1003]; int sum[maxn]; int br = 0; void DFS(vector<int> v) { if (v.size() == n) { bool poss = true; int biggestSeen = 0; for (int i: v) { if (i > biggestSeen+1) { poss = false; break; } biggestSeen = max(biggestSeen,i); } if (poss) { br++; /* for (int i: v) { cout << i << ' '; } cout << '\n'; */ } } else { for (int j = 1; j <= n; j++) { v.push_back(j); DFS(v); v.pop_back(); } } } int brute() { vector<int> v; DFS(v); return br; } int main() { //ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i <= n; i++) { dp[1][i] = i; //cout << dp[1][i] << ' '; } //cout << '\n'; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n+1-i; j++) { dp[i][j] = (j-1)*dp[i-1][j] + dp[i-1][j+1]; //printf("[%d][%d]: %d\n",i,j,dp[i][j]); //cout << dp[i][j] << ' '; madd(sum[i],dp[i][j]); } //cout << '\n'; } int ans = 0; for (int i = 1; i <= n; i++) { madd(ans,dp[n+1-i][a[i]-1]); //cout << ans << '\n'; //curr = dp[n+1-i][a[i]]; } madd(ans,1); cout << dp[n][1] << '\n'; //cout << "brute: " << ' ' << brute() << '\n'; }

Compilation message (stderr)

teams.cpp: In function 'void DFS(std::vector<int>)':
teams.cpp:28:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (v.size() == n) {
         ~~~~~~~~~^~~~
#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...