結果

問題 No.196 典型DP (1)
ユーザー nola_suznola_suz
提出日時 2015-04-27 13:47:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 3,114 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 98,896 KB
実行使用メモリ 35,132 KB
最終ジャッジ日時 2023-09-18 13:51:22
合計ジャッジ時間 4,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,484 KB
testcase_14 AC 3 ms
4,436 KB
testcase_15 AC 8 ms
8,788 KB
testcase_16 AC 13 ms
14,904 KB
testcase_17 AC 27 ms
21,072 KB
testcase_18 AC 55 ms
26,744 KB
testcase_19 AC 47 ms
29,428 KB
testcase_20 AC 80 ms
34,112 KB
testcase_21 AC 89 ms
34,044 KB
testcase_22 AC 81 ms
34,384 KB
testcase_23 AC 467 ms
34,480 KB
testcase_24 AC 424 ms
34,200 KB
testcase_25 AC 396 ms
34,476 KB
testcase_26 AC 22 ms
34,964 KB
testcase_27 AC 22 ms
35,132 KB
testcase_28 AC 22 ms
35,048 KB
testcase_29 AC 22 ms
35,028 KB
testcase_30 AC 22 ms
34,968 KB
testcase_31 AC 56 ms
32,948 KB
testcase_32 AC 55 ms
32,832 KB
testcase_33 AC 55 ms
32,992 KB
testcase_34 AC 54 ms
32,856 KB
testcase_35 AC 55 ms
32,820 KB
testcase_36 AC 54 ms
32,992 KB
testcase_37 AC 38 ms
33,952 KB
testcase_38 AC 54 ms
32,948 KB
testcase_39 AC 50 ms
33,432 KB
testcase_40 AC 55 ms
32,884 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
// #define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

vvll vv;
int n,m;
ll dp[2010][2010];
int used[2010];
ll tmp[2010];
int sz[2010];
ll add(ll a,ll b){
	a%=MOD;
	b%=MOD;
	a+=b;
	a%=MOD;
	return a;
}
void foo2(int a,int n){
	ll ret[2010]={};
	rep(i,n){
		if(dp[a][i])rep(j,n){
			if(i+j>=2010) break;
			ret[i+j]=add(ret[i+j],dp[a][i]*tmp[j]);
		}
	}
	rep(i,2010){
		tmp[i]=ret[i];
	}
	return;
}
void foo(int a){
	// cout<<a<<endl;
	int n=0;
	rep(i,vv[a].size()){
		if(used[vv[a][i]]==0) foo(vv[a][i]);
		n+=sz[vv[a][i]];
	}
	used[a]=1;
	// if(a==2) cout<<"aoao "<<a<<" "<<vv[a].size()<<endl;
	if(vv[a].size()==0){
		dp[a][1]=1LL;
		dp[a][0]=1LL;
		sz[a]=1;
		// puts("end");
		return;
	}
	// puts("aa");
	// return;
	rep(i,2010){
		tmp[i]=dp[vv[a][0]][i];
	}
	reep(i,1,vv[a].size()){
		foo2(vv[a][i],n+1);
	}
	rep(i,2010){
		dp[a][i]=tmp[i];
	}
	dp[a][n+1]=1LL;
	sz[a]=n+1;
	return;
}
void mainmain(){
	cin>>n>>m;
	vv=vvll(n);
	vector<pii> v(n-1);
	rep(i,n-1){
		int a,b;
		cin>>v[i].F>>v[i].S;
	}
	queue<int> q;
	q.push(0);
	while(q.size()){
		int top=q.front();
		q.pop();
		rep(i,v.size()){
			if(v[i].F==top){
				q.push(v[i].S);
				vv[top].PB(v[i].S);
				v.erase(v.begin()+i);
				i--;
			}
			else if(v[i].S==top){
				q.push(v[i].F);
				vv[top].PB(v[i].F);
				v.erase(v.begin()+i);
				i--;
			}
		}
	}
	foo(0);
	cout<<dp[0][m]<<endl;
}


signed main() {
    mainmain();
}
0