国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 web前端 html教學(xué) Codeforces Round #277 (Div. 2)D(樹形DP計(jì)數(shù)類)_html/css_WEB-ITnose

Codeforces Round #277 (Div. 2)D(樹形DP計(jì)數(shù)類)_html/css_WEB-ITnose

Jun 24, 2016 am 11:54 AM

D. Valid Sets

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As you know, an undirected connected graph with?n?nodes and?n?-?1?edges is called a?tree. You are given an integer?d?and a tree consisting of?n?nodes. Each node?i?has a value?ai?associated with it.

We call a set?S?of tree nodes?valid?if following conditions are satisfied:

  1. S?is non-empty.
  2. S?is connected. In other words, if nodes?u?and?v?are in?S, then all nodes lying on the simple path between?u?and?v?should also be presented in?S.
  3. .

Your task is to count the number of valid sets. Since the result can be very large, you must print its remainder modulo?1000000007(109?+?7).

Input

The first line contains two space-separated integers?d?(0?≤?d?≤?2000) and?n?(1?≤?n?≤?2000).

The second line contains?n?space-separated positive integers?a1,?a2,?...,?an(1?≤?ai?≤?2000).

Then the next?n?-?1?line each contain pair of integers?u?and?v?(1?≤?u,?v?≤?n) denoting that there is an edge between?u?and?v. It is guaranteed that these edges form a tree.

Output

Print the number of valid sets modulo?1000000007.

Sample test(s)

input

1 42 1 3 21 21 33 4

output

input

0 31 2 31 22 3

output

input

4 87 8 7 5 4 6 4 101 61 25 81 33 56 73 4

output

41

Note

In the first sample, there are exactly 8 valid sets:?{1},?{2},?{3},?{4},?{1,?2},?{1,?3},?{3,?4}?and?{1,?3,?4}. Set?{1,?2,?3,?4}?is not valid, because the third condition isn't satisfied. Set?{1,?4}?satisfies the third condition, but conflicts with the second condition.


題意:RT


思路:樹形DP,dp[u]表示以u為根,且它的所有子樹的點(diǎn)v的權(quán)值都不超過它,且滿足 w[u]-w[v]


? ? ? ? ? ? 對于每個(gè)點(diǎn)為根這樣算一遍就好了,注意減去算重的情況,即相鄰多個(gè)點(diǎn)的權(quán)值相等,可以用點(diǎn)的代號去重(即規(guī)定只能從代號大的往小的DP)


本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

我如何了解最新的HTML標(biāo)準(zhǔn)和最佳實(shí)踐? 我如何了解最新的HTML標(biāo)準(zhǔn)和最佳實(shí)踐? Jun 20, 2025 am 08:33 AM

要跟上HTML標(biāo)準(zhǔn)和最佳實(shí)踐,關(guān)鍵在於有意為之而非盲目追隨。首先,關(guān)注官方來源如WHATWG和W3C的摘要或更新日誌,了解新標(biāo)籤(如)和屬性,將其作為參考解決疑難問題;其次,訂閱可信的網(wǎng)頁開發(fā)新聞通訊和博客,每週花10-15分鐘瀏覽更新,關(guān)注實(shí)際用例而非僅收藏文章;再次,使用開發(fā)者工具和linters如HTMLHint,通過即時(shí)反饋優(yōu)化代碼結(jié)構(gòu);最後,與開發(fā)者社區(qū)互動(dòng),分享經(jīng)驗(yàn)並學(xué)習(xí)他人實(shí)戰(zhàn)技巧,從而持續(xù)提升HTML技能。

如何最小化HTML文件的大小? 如何最小化HTML文件的大??? Jun 24, 2025 am 12:53 AM

要減小HTML文件大小需清理冗余代碼、壓縮內(nèi)容并優(yōu)化結(jié)構(gòu)。1.刪除未使用的標(biāo)簽、注釋和多余空白以減少體積;2.將內(nèi)聯(lián)CSS和JavaScript移至外部文件并合并多個(gè)腳本或樣式塊;3.在不影響解析的前提下簡化標(biāo)簽語法,如省略可選閉合標(biāo)簽或使用簡短屬性;4.清理后啟用Gzip或Brotli等服務(wù)器端壓縮技術(shù)進(jìn)一步縮減傳輸體積。這些步驟可在不犧牲功能的前提下顯著提升頁面加載性能。

隨著時(shí)間的流逝,HTML如何發(fā)展,其歷史上的關(guān)鍵里程碑是什麼? 隨著時(shí)間的流逝,HTML如何發(fā)展,其歷史上的關(guān)鍵里程碑是什麼? Jun 24, 2025 am 12:54 AM

htmlhasevolvedscreatscreationtomeetthegrowingdemandsofwebdevelopersandusers.inatelyallyasimplemarkuplanguageforsharingdocuments,ithasundergonemajorupdates,包括html.2.0,包括wheintrodistusefforms;

如何使用元素代表文檔或部分的頁腳? 如何使用元素代表文檔或部分的頁腳? Jun 25, 2025 am 12:57 AM

是HTML5中用於定義頁面或內(nèi)容區(qū)塊底部的語義化標(biāo)籤,通常包含版權(quán)信息、聯(lián)繫方式或?qū)Ш芥溄拥龋凰芍渺俄撁娴撞炕蚯短自?、等?biāo)籤內(nèi)作為區(qū)塊尾部;使用時(shí)應(yīng)注意避免重複濫用及放入無關(guān)內(nèi)容。

如何使用Tabindex屬性來控制元素的選項(xiàng)卡順序? 如何使用Tabindex屬性來控制元素的選項(xiàng)卡順序? Jun 24, 2025 am 12:56 AM

ThetabindexattributecontrolshowelementsreceivefocusviatheTabkey,withthreemainvalues:tabindex="0"addsanelementtothenaturaltaborder,tabindex="-1"allowsprogrammaticfocusonly,andtabindex="n"(positivenumber)setsacustomtabbing

如何使用元素將視頻嵌入HTML中? 如何使用元素將視頻嵌入HTML中? Jun 20, 2025 am 10:09 AM

要在HTML中嵌入視頻,需使用標(biāo)籤並指定視頻源與屬性。 1.使用src屬性或元素定義視頻路徑和格式;2.添加controls、width、height等基本屬性;3.為兼容不同瀏覽器,可列舉MP4、WebM、Ogg等多種格式;4.使用controls、autoplay、muted、loop、preload等屬性控製播放行為;5.通過CSS實(shí)現(xiàn)響應(yīng)式佈局,確保適配不同屏幕。正確結(jié)構(gòu)與屬性組合能確保視頻良好顯示與功能支持。

聲明是什麼,它做什麼? 聲明是什麼,它做什麼? Jun 24, 2025 am 12:57 AM

Adeclarationisaformalstatementthatsomethingistrue,official,orrequired,usedtoclearlydefineorannounceanintent,fact,orrule.Itplaysakeyroleinprogrammingbydefiningvariablesandfunctions,inlegalcontextsbyreportingfactsunderoath,andindailylifebymakingintenti

如何使用元素在HTML中創(chuàng)建文本區(qū)域? 如何使用元素在HTML中創(chuàng)建文本區(qū)域? Jun 25, 2025 am 01:07 AM

要?jiǎng)?chuàng)建HTML文本區(qū)域,使用元素,並通過屬性和CSS進(jìn)行定制。 1.使用基本語法定義文本區(qū)域並設(shè)置rows、cols、name、placeholder等屬性;2.可通過CSS精確控制大小及樣式,如width、height、padding、border等;3.提交表單時(shí)通過name屬性識別數(shù)據(jù),也可用JavaScript獲取值進(jìn)行前端處理。

See all articles