結果
| 問題 | No.389 ロジックパズルの組み合わせ | 
| コンテスト | |
| ユーザー |  wing3196 | 
| 提出日時 | 2016-07-08 23:01:06 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 63 ms / 2,000 ms | 
| コード長 | 741 bytes | 
| コンパイル時間 | 1,212 ms | 
| コンパイル使用メモリ | 161,472 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-13 06:28:26 | 
| 合計ジャッジ時間 | 4,319 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 99 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000000 + 7;
int Factorial(int n)
{
	int res = 1;
	while (n) (res *= n--) %= MOD;
	return res;
}
int Pow(int x, int n)
{
	if (n == 0) return 1;
	int res = Pow(x*x % MOD, n/2);
	if (n&1) res *= x;
	return res % MOD;
}
int Inverse(int n)
{
	return Pow(n, MOD - 2);
}
int H(int ball, int stick)
{
	return Factorial(ball + stick) * Inverse(Factorial(ball) * Factorial(stick) % MOD) % MOD;
}
int M;
signed main()
{
	cin >> M;
	int h, sum = 0, N = 0;
	while (cin >> h)
	{
		sum += h;
		N++;
	}
	if (h == 0) sum = 0, N = 0;
	if (sum + N - 1 > M)
	{
		puts("NA");
		return 0;
	}
	int n = M - (sum + N - 1), k = N;
	printf("%lld\n", H(n, k));
	return 0;
}
            
            
            
        