日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

杭电多校第六场-J-Ridiculous Netizens

發(fā)布時(shí)間:2025/10/17 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 杭电多校第六场-J-Ridiculous Netizens 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Problem Description

Mr. Bread has a tree?T?with?n?vertices, labeled by?1,2,,n. Each vertex of the tree has a positive integer value?wi.

The value of a non-empty tree?T?is equal to?w1×w2×?×wn. A subtree of?T?is a connected subgraph of?T?that is also a tree.

Please write a program to calculate the number of non-empty subtrees of?T?whose values are not larger than a given number?m.

Input

The first line of the input contains an integer?T(1T10), denoting the number of test cases.

In each test case, there are two integers?n,m(1n2000,1m106)?in the first line, denoting the number of vertices and the upper bound.

In the second line, there are?n?integers?w1,w2,,wn(1wim), denoting the value of each vertex.

Each of the following?n?1?lines contains two integers?ui,vi(1ui,vin,uivi), denoting an bidirectional edge between vertices?ui?and?vi.

Output

For each test case, print a single line containing an integer, denoting the number of valid non-empty subtrees. As the answer can be very large, output it modulo?10^9+7.

Sample Input

1 5 6 1 2 1 2 3 1 2 1 3 2 4 2 5

Sample Output

14

?

題意: 一棵無根樹,每個(gè)點(diǎn)有權(quán)值,詢問有多少個(gè)聯(lián)通子圖的權(quán)值的積等于m

思路
https://www.cnblogs.com/hua-dong/p/11320013.html
考慮對(duì)某點(diǎn),聯(lián)通塊要么經(jīng)過它要么不經(jīng)過它 ——> 點(diǎn)分治
對(duì)于經(jīng)過該點(diǎn)的用dp求解
在dfs序上dp,類似于樹形依賴背包
dp[i][j]表示 dfs序i之后的乘積為j的方案數(shù)
可知 dp[i][j]=(dp[i+1][j/a[dfn[i]]]+dp[i+son[i]][j]) //當(dāng)前點(diǎn)選/不選
但第二維為m不可行
考慮把<sqrt(M)的和大于sqrt(M)的分開保存,那么前者就是正常的背包,表示當(dāng)前乘積;后者可以看成以后還可以取多少
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define ll long long using namespace std; const int N=1e5+10; const int p=1e9+7; int T,n,m,cnt,sum,root,tim,ans; struct orz{int v,nex;}e[N*2]; int a[N],last[N],son[N],f[N],dfn[N],dp1[N][1005],dp2[N][1005]; bool vis[N]; void add(int x,int y) {cnt++;e[cnt].v=y;e[cnt].nex=last[x];last[x]=cnt; } void getroot(int x,int fa) {son[x]=1; f[x]=0;for (int i=last[x];i;i=e[i].nex){if (e[i].v==fa || vis[e[i].v]) continue;getroot(e[i].v,x);son[x]+=son[e[i].v];f[x]=max(f[x],son[e[i].v]);}f[x]=max(f[x],sum-son[x]);if (f[x]<f[root]) root=x; } void dfs(int x,int fa) {dfn[++tim]=x; son[x]=1;for (int i=last[x];i;i=e[i].nex){if (e[i].v==fa || vis[e[i].v]) continue;dfs(e[i].v,x);son[x]+=son[e[i].v];} } void cal() {int mm=sqrt(m);for (int i=1;i<=tim+1;i++){memset(dp1[i],0,sizeof(dp1[i]));memset(dp2[i],0,sizeof(dp2[i]));}dp1[tim+1][1]=1;for (int i=tim;i>=1;i--){int x=a[dfn[i]];for (int j=1;j<=min(mm,m/x);j++){int k=j*x;if (k<=mm) dp1[i][k]=(dp1[i][k]+dp1[i+1][j])%p;else dp2[i][m/k]=(dp2[i][m/k]+dp1[i+1][j])%p;}for (int j=x;j<=mm;j++){dp2[i][j/x]=(dp2[i][j/x]+dp2[i+1][j])%p;}for (int j=1;j<=mm;j++){dp1[i][j]=(dp1[i][j]+dp1[i+son[dfn[i]]][j])%p;dp2[i][j]=(dp2[i][j]+dp2[i+son[dfn[i]]][j])%p;}}for (int i=1;i<=mm;i++){ans=(ans+dp1[1][i])%p;ans=(ans+dp2[1][i])%p;}ans=(ans-1+p)%p; } void work(int x) {//cout<<x<<endl;vis[x]=1; tim=0;dfs(root,0); //for (int i=1;i<=tim;i++) cout<<dfn[i]<<' '; cout<<endl; cal();for (int i=last[x];i;i=e[i].nex){if (vis[e[i].v]) continue;sum=son[e[i].v];root=0;getroot(e[i].v,root);work(root);} } void init() {cnt=0; ans=0;for (int i=1;i<=n;i++) last[i]=0,vis[i]=0; } int main() {scanf("%d",&T);while(T--){scanf("%d%d",&n,&m);init();for (int i=1;i<=n;i++) scanf("%d",&a[i]);int x,y;for (int i=1;i<n;i++){scanf("%d%d",&x,&y);add(x,y); add(y,x);}sum=n; f[0]=inf;getroot(1,0);work(root);printf("%d\n",ans);}return 0; } View Code

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/tetew/p/11366398.html

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的杭电多校第六场-J-Ridiculous Netizens的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲中文无码久久 | 中文字幕一区二区三区在线播放 | 91精品国产自产91精品 | 黄色复仇草 | 炕上如狼似虎的呻吟声 | 欧美一卡二卡 | 澳门av网站 | 激情欧美亚洲 | 亚洲欧美bt| 手机看片国产精品 | 久久情趣视频 | 亚洲精品男女 | a视频免费 | 一区二区三区网站 | 男人午夜网站 | 成人国产av一区二区三区 | 香蕉视频国产在线观看 | 浮力影院国产第一页 | 欧美日韩一区二区三区 | 超碰资源总站 | 淫视频网站 | 厨房性猛交hd | 日本成人免费网站 | 久操这里只有精品 | a黄色片 | 亚洲一区二区三区国产 | 伊人久久青青草 | 在线观看成人动漫 | 日韩亚洲欧美一区二区三区 | 欧美精品免费看 | 91国产免费观看 | 日韩在线第一 | 男女做爰猛烈刺激 | 一级黄色片视频 | 久久久久久久国产精品毛片 | 久久少妇av | 日韩小视频在线观看 | 黄色三级带 | 五月婷婷一区二区三区 | 欧美精品三级 | 久久一级大片 | 亚洲福利一区二区 | 国产女人在线视频 | 午夜在线视频播放 | hd性videos意大利精品 | 国产一区二区三区高清 | 久在操| 色av综合| 亚洲精品乱 | 偷拍第1页| 国产精品交换 | 香蕉久久久久 | 草视频在线观看 | 欧美一区二区三区激情视频 | 精品国偷自产一区二区三区 | 一区二区精品在线 | 美女网站免费视频 | 欧美激情综合色综合啪啪五月 | 欧美老熟妇喷水 | 久久久久夜夜夜精品国产 | 午夜亚洲成人 | 国产精品高潮呻吟 | 日韩精品网站 | 久久亚洲美女 | 97av视频在线| 99碰碰 | 亚洲成人免费在线观看 | 丰满女邻居的色诱4hd | 黄色骚视频 | 丰满少妇在线观看网站 | 真人毛片视频 | 黄色网页免费观看 | 精品久久久久成人码免费动漫 | www久久久 | 性激烈视频在线观看 | 国产三级免费观看 | 成人一区二区三区在线观看 | 国产淫视| 亚洲女同二女同志 | 久久综合视频网 | 欧美二级片 | 波多野结衣在线免费观看视频 | 欧美性网站 | 国产精品三级在线 | 波多野结衣久久精品 | 日本三级视频 | 国产在线观看一区 | 欧美国产日韩视频 | 在线视频三区 | 国产又粗又大又爽视频 | 香蕉视频一区 | 2019国产在线| 人乳videos巨大吃奶 | 日本精品久久久久中文字幕 | 男男做的视频 | 日韩少妇一区二区 | 日本综合视频 | 成人三级在线看 | 久久精品美乳 |