Submission #208052

# Submission time Handle Problem Language Result Execution time Memory
208052 2020-03-09T21:34:18 Z eggag32 Zapina (COCI20_zapina) C++17
0 / 110
5 ms 376 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll dp[355][355][355][2]; //[index][current number][tot][already have one happy]

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	rep(i, n + 2) rep(j, n + 2) rep(k, n + 2) rep(l, 2) dp[i][j][k][l] = 0;
	dp[1][1][1][1] = 1;
	repn(i, 0, n + 1) if(i != 1) dp[1][i][i][0] = 1;
	//debug(dp[1][0][0][0]);
	repn(i, 2, n + 1){
		repn(j, 0, n + 1){ //the prev total
			repn(k, 0, n + 1) if((j + k) <= n){ //current choice
				repn(l, 0, n + 1) if(j >= l){ //prev choice
					//cout << i << " " << j << " " << k << " " << l << endl;
					dp[i][j][j + k][l] = 1;
					if(k == i){
						//debug2(i, j);
						//debug2(k, l);
						//debug(dp[i - 1][l][j][1]);
						//debug2(l, j);
						//debug(dp[i - 1][l][j][0]);
						dp[i][k][j + k][1] = (dp[i][k][j + k][1] + dp[i - 1][l][j][1] + dp[i - 1][l][j][0]) % MOD;
						//debug(dp[i - 1][l][j][1]);
						dp[i][k][j + k][0] = (dp[i][k][j + k][0] + dp[i - 1][l][j][0]) % MOD;
					}
					else{
						dp[i][k][j + k][1] = (dp[i][k][j + k][1] + dp[i - 1][l][j][1]) % MOD;
						dp[i][k][j + k][0] = (dp[i][k][j + k][0] + dp[i - 1][l][j][0]) % MOD;
					}
				}
			}
		}
	}
	ll ans = 0;
	repn(i, 0, n + 1) ans = (ans + dp[n][i][n][1]) % MOD;
	//debug(dp[2][1][n][1]);
	//debug(dp[2][2][n][1]);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -