Submission #208056

# Submission time Handle Problem Language Result Execution time Memory
208056 2020-03-09T21:42:21 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][2]; //[index][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, 2) dp[i][j][k] = 0;
	dp[1][1][1] = 1;
	repn(i, 0, n + 1) if(i != 1) dp[1][i][0] = 1;
	repn(i, 2, n + 1){
		repn(j, 0, n + 1){ //the prev total
			repn(k, 0, n + 1) if((j + k) <= n){ //current choice
				//cout << i << " " << j << " " << k << " " << l << endl;
				dp[i][j + k][0] = 1;
				if(k == i) dp[i][j + k][1] = 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][j + k][1] = (dp[i][j + k][1] + dp[i - 1][j][1] + dp[i - 1][j][0]) % MOD;
					//debug(dp[i - 1][l][j][1]);
					dp[i][j + k][0] = (dp[i][j + k][0] + dp[i - 1][j][0]) % MOD;
				}
				else{
					dp[i][j + k][1] = (dp[i][j + k][1] + dp[i - 1][j][1]) % MOD;
					dp[i][j + k][0] = (dp[i][j + k][0] + dp[i - 1][j][0]) % MOD;
				}
			}
		}
	}
	ll ans = 0;
	ans = (ans + dp[n][n][1]) % MOD;
	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 -