Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created June 1, 2015 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luccasiau/7d9747e50d431f9e6e3e to your computer and use it in GitHub Desktop.
Save luccasiau/7d9747e50d431f9e6e3e to your computer and use it in GitHub Desktop.
//
// 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