結果
| 問題 |
No.196 典型DP (1)
|
| コンテスト | |
| ユーザー |
DAyamaCTF
|
| 提出日時 | 2018-09-24 20:38:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 1,415 bytes |
| コンパイル時間 | 1,749 ms |
| コンパイル使用メモリ | 162,744 KB |
| 実行使用メモリ | 54,684 KB |
| 最終ジャッジ日時 | 2024-09-23 05:15:34 |
| 合計ジャッジ時間 | 3,706 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | scanf("%lld%lld",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:63:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
ll N,K;
ll cnt[5001];
ll dp[5001][5001];
ll dp2[2][5001];
vector<int> g[5001];
void dfs(int v,int pre){
cnt[v]=1;
for(int nv : g[v]){
if(nv==pre)continue;
dfs(nv,v);
cnt[v]+=cnt[nv];
}
int crt=0,nxt=1;
rep(j,cnt[v]+1)dp2[crt][j]=0;
dp2[crt][0]=1;
for(int nv : g[v]){
if(nv==pre)continue;
rep(j,cnt[v]+1)dp2[nxt][j]=0;
rep(j,cnt[v]+1){
if(dp2[crt][j]==0)break;
rep(k,cnt[nv]+1){
if(j+k<cnt[v])(dp2[nxt][j+k]+=dp2[crt][j]*dp[nv][k]%mod)%=mod;
else break;
}
}
swap(crt,nxt);
}
rep(j,cnt[v]){
dp[v][j]=dp2[crt][j];
}
dp[v][cnt[v]]=1;
}
int main(){
scanf("%lld%lld",&N,&K);
rep(i,N-1){
int a,b;
scanf("%d%d",&a,&b);
g[a].push_back(b); g[b].push_back(a);
}
dfs(0,-1);
cout<<dp[0][K]<<endl;
return 0;
}
DAyamaCTF