Advertisement
Guest User

G TAP 2017

a guest
Oct 22nd, 2017
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define dprint(v) cerr << #v"=" << v << endl //;)
  4. #define forr(i,a,b) for(int i=(a); i<(b); i++)
  5. #define forn(i,n) forr(i,0,n)
  6. #define dforn(i,n) for(int i=n-1; i>=0; i--)
  7. #define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
  8. #define sz(c) ((int)c.size())
  9. #define zero(v) memset(v, 0, sizeof(v))
  10. #define pb push_back
  11. #define fst first
  12. #define snd second
  13. typedef long long ll;
  14. typedef pair<int,int> ii;
  15.  
  16. const ll MOD = 1e9+7;
  17. int N,M,P1,P2;
  18. ll comb[110][110], dp[110][1010];
  19.  
  20. int main() {
  21.     //~ freopen("in", "r", stdin);
  22.     ios::sync_with_stdio(0);
  23.     while(cin >> N >> M >> P1 >> P2){
  24.         dp[0][0]=1;
  25.         forr(p,1,1001) dp[0][p]=0;
  26.         forr(x,1,N+1) forn(p,1001) {
  27.             dp[x][p] = 0;
  28.             forr(i,1,min(p,M)+1) {
  29.                 dp[x][p] = (dp[x][p]+dp[x-1][p-i])%MOD;
  30.             }
  31.         }
  32.         forn(i, 105){
  33.             comb[i][0]=comb[i][i]=1;
  34.             forr(k, 1, i) comb[i][k]=(comb[i-1][k]+comb[i-1][k-1])%MOD;
  35.         }
  36.         ll ans = 0;
  37.         forn(x,N+1) forn(y,N-x+1) {
  38.             ll aux = (dp[x][P1]*dp[y][P2])%MOD;
  39.             aux = (aux*comb[N][x])%MOD;
  40.             aux = (aux*comb[N-x][y])%MOD;
  41.             //~ cout << x << " " << aux << endl;
  42.             ans = ( ans + aux ) % MOD;
  43.         }
  44.         cout << ans << endl;
  45.    
  46.     }
  47.     return 0;
  48. }
Advertisement
RAW Paste Data Copied
Advertisement