結果

問題 No.196 典型DP (1)
ユーザー nola_suznola_suz
提出日時 2015-04-27 13:39:59
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,102 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 100,316 KB
実行使用メモリ 37,152 KB
最終ジャッジ日時 2023-09-18 13:51:01
合計ジャッジ時間 9,266 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,596 KB
testcase_15 AC 12 ms
8,816 KB
testcase_16 AC 41 ms
15,040 KB
testcase_17 AC 79 ms
21,076 KB
testcase_18 AC 204 ms
26,784 KB
testcase_19 AC 199 ms
29,500 KB
testcase_20 AC 246 ms
33,948 KB
testcase_21 AC 262 ms
33,972 KB
testcase_22 AC 197 ms
34,116 KB
testcase_23 AC 926 ms
34,452 KB
testcase_24 AC 849 ms
34,204 KB
testcase_25 AC 881 ms
34,240 KB
testcase_26 AC 21 ms
34,972 KB
testcase_27 AC 21 ms
35,008 KB
testcase_28 AC 21 ms
35,032 KB
testcase_29 AC 20 ms
35,040 KB
testcase_30 AC 21 ms
35,008 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
		rep(j,n){
			if(i+j>=2010) break;
			ret[i+j]=add(ret[i+j],tmp[i]*dp[a][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