2020-03-07 13:12:04 C++

C++

Copy Copied! Full
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 }; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int ans; int n,s,k; void dfs(int d,int prev,int sum){ if(sum>s)return; if(d == n && sum == s){ ans++; ans %= mod; return; } if(d==n)return; for(int i=prev;i<=s;i++){ dfs(d+1,i,sum+i); } } int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cin >> n >> s >> k; s -= ((0+n-1)*n)*k/2; if(s<0){ cout << 0 << endl; return 0; }else{ cout << s << endl; rep(i,s+1)dfs(1,i,i); cout << ans << endl; } }
RECOMMEND