結果

問題 No.196 典型DP (1)
ユーザー kotatsugamekotatsugame
提出日時 2020-10-09 19:22:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,623 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 71,912 KB
実行使用メモリ 19,064 KB
最終ジャッジ日時 2023-09-27 13:51:37
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
6,604 KB
testcase_16 AC 3 ms
8,612 KB
testcase_17 AC 6 ms
12,704 KB
testcase_18 AC 7 ms
14,864 KB
testcase_19 AC 9 ms
16,792 KB
testcase_20 AC 10 ms
17,472 KB
testcase_21 AC 9 ms
17,472 KB
testcase_22 AC 9 ms
17,500 KB
testcase_23 AC 10 ms
18,124 KB
testcase_24 AC 9 ms
17,848 KB
testcase_25 AC 10 ms
17,872 KB
testcase_26 AC 10 ms
19,056 KB
testcase_27 AC 11 ms
18,904 KB
testcase_28 AC 10 ms
18,896 KB
testcase_29 AC 10 ms
19,064 KB
testcase_30 AC 10 ms
18,932 KB
testcase_31 AC 13 ms
17,732 KB
testcase_32 AC 13 ms
17,416 KB
testcase_33 AC 13 ms
17,688 KB
testcase_34 AC 13 ms
17,604 KB
testcase_35 AC 13 ms
17,420 KB
testcase_36 AC 13 ms
17,604 KB
testcase_37 AC 9 ms
17,684 KB
testcase_38 AC 12 ms
17,476 KB
testcase_39 AC 12 ms
17,484 KB
testcase_40 AC 14 ms
17,420 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:27:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<vector>
using namespace std;
#line 3 "/home/kotatsugame/library/math/modint.cpp"
#include<utility>
template<int m>
struct modint{
	unsigned int x;
	constexpr modint()noexcept:x(){}
	constexpr modint(long long _x)noexcept:x((_x%=m)<0?_x+m:_x){}
	constexpr unsigned int val()const noexcept{return x;}
	constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;}
	constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;}
	constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;}
	constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;}
	constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;}
	constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;}
	constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;}
	constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();}
	constexpr modint operator+()const noexcept{return*this;}
	constexpr modint operator-()const noexcept{return modint()-*this;}
	constexpr modint pow(long long n)const noexcept
	{
		if(n<0)return pow(-n).inv();
		modint x=*this,r=1;
		for(;n;x*=x,n>>=1)if(n&1)r*=x;
		return r;
	}
	constexpr modint inv()const noexcept
	{
		int s=x,t=m,x=1,u=0;
		while(t)
		{
			int k=s/t;
			s-=k*t;
			swap(s,t);
			x-=k*u;
			swap(x,u);
		}
		return modint(x);
	}
	friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
	friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
	friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
	friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
	friend constexpr modint operator==(const modint&a,const modint&b){return a.x==b.x;}
	friend constexpr modint operator!=(const modint&a,const modint&b){return a.x!=b.x;}
	friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;}
	friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;}
};
#line 5 "a.cpp"
using mint=modint<(int)1e9+7>;
int N,K;
vector<int>G[2000];
mint dp[2000][2001];
int dfs(int u,int p)
{
	int ch=0;
	dp[u][0]=1;
	for(int v:G[u])if(v!=p)
	{
		int x=dfs(v,u);
		for(int i=ch;i>=0;i--)
		{
			mint now=dp[u][i];
			dp[u][i]=0;
			for(int j=0;j<=x;j++)dp[u][i+j]+=now*dp[v][j];
		}
		ch+=x;
	}
	dp[u][++ch]=1;
	return ch;
}
main()
{
	cin>>N>>K;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1);
	cout<<dp[0][K]<<endl;
}
0