結果

問題 No.1667 Forest
ユーザー kotatsugamekotatsugame
提出日時 2021-09-03 22:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 703 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 67,032 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-09 04:54:31
合計ジャッジ時間 4,035 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 10 ms
5,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 99 ms
5,376 KB
testcase_09 AC 59 ms
5,376 KB
testcase_10 AC 30 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N,mod;
long modpow(long a,long b){return b?modpow(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long T[301];
long dp[301][301];
long fac[301],invfac[301];
long ans[301];
long comb(int a,int b){return fac[a]*invfac[b]%mod*invfac[a-b]%mod;}
main()
{
	cin>>N>>mod;
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=fac[i-1]*i%mod;
	invfac[N]=modpow(fac[N],mod-2);
	for(int i=N;i--;)invfac[i]=invfac[i+1]*(i+1)%mod;
	T[1]=1;
	for(int k=2;k<=N;k++)T[k]=modpow(k,k-2);
	dp[0][0]=1;
	for(int c=0;c<N;c++)
	{
		for(int i=0;i<=N;i++)
		{
			for(int k=1;i+k<=N;k++)
			{
				(dp[c+k-1][i+k]+=dp[c][i]*comb(N-i-1,k-1)%mod*T[k]%mod)%=mod;
			}
		}
	}
	for(int i=0;i<N;i++)cout<<dp[i][N]<<endl;
}
0