Created
June 1, 2015 03:14
-
-
Save luccasiau/7d9747e50d431f9e6e3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// baile_de_formatura.cpp | |
// | |
// Created by Lucca Siaudzionis on 19/11/14. | |
// Copyright (c) 2014 Luccasiau. All rights reserved. | |
// | |
#include <cstdio> | |
#define MOD 1000000007 | |
typedef long long lli; | |
#define MAXN 1010 | |
int g, b; | |
lli fact[MAXN]; | |
lli ways[MAXN][MAXN]; | |
int main(){ | |
fact[0] = 1LL; | |
for(int i = 1;i < MAXN;i++) | |
fact[i] = (lli(i)*fact[i-1]) % MOD; | |
for(int i = 1;i < MAXN;i++) | |
ways[1][i] = 1LL, | |
ways[i][i] = fact[i]; | |
for(int i = 2;i < MAXN;i++) | |
for(int j = i+1;j < MAXN;j++) | |
ways[i][j] = (lli(i)*( ways[i][j-1] + ways[i-1][j-1] )) % MOD; | |
while(scanf("%d %d", &b, &g) && b) printf("%lld\n", ways[g][b]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment