제출 #487350

#제출 시각아이디문제언어결과실행 시간메모리
487350LptN21Zapina (COCI20_zapina)C++14
110 / 110
117 ms1832 KiB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define PI acos(-1.0)
#define FF first
#define SS second
#define eps 1e-3
// vector
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define lb lower_bound
#define ub upper_bound
// bit
#define CNTBIT(x) __builtin_popcount(x)
#define ODDBIT(x) __builtin_parity(x)
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
typedef pair<int, ii> i3;
/* CODE BELOW */
const int N=350+7, M=17+1, K=243+1;
const int MOD=1e9+7;
const int oo=1e9+7;

int n, m, k, t;

int _dp[N][N][2];
int C[N][N];

int add(int a, int b) {
    a+=b; if(a>=MOD) a-=MOD;
    return a;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
void upd(int &a, int b) {
    a+=b; if(a>=MOD) a-=MOD;
}

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d", &n);
    _dp[0][0][0]=1, C[0][0]=1;

    for(int i=1;i<=n;i++) {
        for(int j=1;j<=i;j++) {
            C[i][j]=add(C[i-1][j], C[i-1][j-1]);
        }
        C[i][0]=1;
    }

    for(int i=1;i<=n;i++) {
        for(int j=0;j<=n;j++) {
            for(int k=0;k<=j;k++) {
                if(i==k) {
                    upd(_dp[i][j][1], mul(add(_dp[i-1][j-k][0], _dp[i-1][j-k][1]), C[n+k-j][k]));
                } else {
                    upd(_dp[i][j][1], mul(_dp[i-1][j-k][1], C[n+k-j][k]));
                    upd(_dp[i][j][0], mul(_dp[i-1][j-k][0], C[n+k-j][k]));
                }
            }
            //printf("%d %d | %d %d\n", i, j, _dp[i][j][0], _dp[i][j][1]);
        }
    }

    printf("%d", _dp[n][n][1]);

    return 0;
}
/* stuff you should look for
    - int overflow, array bounds
    - special/edge cases (n=1?)
    - do smth instead of nothing and stay organized
    - WRITE STUFF DOWN
    - DONT JUST STICK ON ONE APPROACH
*/

컴파일 시 표준 에러 (stderr) 메시지

zapina.cpp: In function 'int main()':
zapina.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...