이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 1, n)
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 400;
const ll MOD = 1e9+7;
const ll INF = 1e18;
int n, dp[2][N][N], 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 (ll) a * b % MOD;
}
int get(int check, int rem, int cur){
if(cur == n+1){
if(rem != 0) return 0;
return check;
}
if(rem == 0) return check;
if(dp[check][rem][cur] != -1) return dp[check][rem][cur];
int res = 0;
FOR(i, 0, rem){
///How many different way to choose i from rem
res = add(res, mul(C[rem][i], get((check | (cur == i)), rem - i, cur+1)));
}
return dp[check][rem][cur] = res;
}
void solve()
{
cin >> n;
memset(dp, -1, sizeof(dp));
C[0][0] = 1;
REP(i, n){
FOR(j, 0, i){
C[i][j] = C[i-1][j];
if(j) C[i][j] = add(C[i][j], C[i-1][j-1]);
}
}
cout << get(0, n, 1) <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zapina.cpp: In function 'int main()':
zapina.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
zapina.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |