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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Little penguin Polo loves his home village. The village has?n?houses, indexed by integers from 1 to?n. Each house has a plaque containing an integer, the?i-th house has a plaque containing integer?pi?(1?≤?pi?≤?n).

Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number?x. Then he goes to the house whose number is written on the plaque of house?x?(that is, to house?px), then he goes to the house whose number is written on the plaque of house?px?(that is, to house?ppx), and so on.

We know that:

  • When the penguin starts walking from any house indexed from 1 to?k, inclusive, he can walk to house number 1.
  • When the penguin starts walking from any house indexed from?k?+?1?to?n, inclusive, he definitely cannot walk to house number 1.
  • When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house.
  • You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by?1000000007?(109?+?7).

    Input

    The single line contains two space-separated integers?n?and?k?(1?≤?n?≤?1000,?1?≤?k?≤?min(8,?n)) — the number of the houses and the number?k?from the statement.

    Output

    In a single line print a single integer — the answer to the problem modulo?1000000007?(109?+?7).

    Examples

    Input

    5 2

    Output

    54

    Input

    7 4

    Output

    1728

    題目大意:

    給定 n 和k,n 表示有n個房子,然后每個有一個編號,一只鵝要從一個房間中開始走,下一站就是房間的編號,現在要你求出有多少種方法編號并滿足下面的要求:
    1.如果從1到k開始走,一定能走到 1。

    2.如果從k+1到n 開始走,一定走不到 1.

    3.如果從 1 開始走,那么一定能回到1,并且走過房間數不為0.

    解題報告:

    ? 做這個題涉及到一個結論,,(當然不知道這個結論,這題中也可以通過規律看出來)。

    ? 有一種序列叫,Purfer序列,有一個定理叫Cayley定理。

    Cayley定理:有n個節點的完全圖的生成樹的數量是,或者說n個節點的帶標號的無根樹有個。

    Prufer編碼:給定一棵帶標號的無根樹,找出編號最小的葉子節點,寫下與它相鄰的節點的編號,然后刪掉這個葉子節點。反復執行這個操作直到只剩兩個節點為止。

    感謝wjh大佬的講解orz(鏈接)

    所以對于k前面一部分就是k^(k-1)了,,后面一部分很好推出來是(n-k)^(n-k)。求和就行了。

    (因為通過題意很容易得出結論,,1~k 和 k+1~n? 這倆區間不能有交集的,,也就是 互相不可達的。所以分開求就好了)

    其實前半部分能想成是一棵樹的結構就不容易啊2333.、、

    AC代碼:

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll mod = 1e9 + 7; ll f[MAX],n,k; ll qpow(ll a,ll k) {ll res = 1;while(k) {if(k&1) {res = (res*a)%mod;}k>>=1;a = (a*a)%mod;}return res%mod; } int main() {f[1]=0;f[2]=1;for(int i = 3; i<=1005; i++) {f[i] = (i-1) * ((f[i-1]+f[i-2])%mod)%mod; // printf("%lld\n",f[i]);}cin>>n>>k;printf("%lld\n",(qpow(k,k-1)*qpow(n-k,n-k))%mod);return 0 ;}

    ?

    總結

    以上是生活随笔為你收集整理的【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 天天插天天色 | 亚洲国产精品无码久久久久高潮 | 国产毛片在线 | 日韩精品人妻一区二区中文字幕 | 中文字幕av日韩 | 在线一二区 | 91蝌蚪91九色 | 99视频在线观看免费 | 国产性生活 | 欧美色欧美色 | 日日干天天射 | 欧美日韩99| 欧美淫| 三级性生活片 | 九九精品在线观看视频 | 在线你懂得| 亚洲黄色片免费看 | 亚洲精品二区三区 | a级欧美 | 亚洲人女屁股眼交6 | 99re7| 成人片免费看 | 性欧美bbw| 91看视频| 亚洲在线视频 | 娇小激情hdxxxx学生 | 中国肥胖女人真人毛片 | 日日夜夜操视频 | 在线免费成人 | 少妇淫片 | 欧美午夜久久 | 色涩网站 | 亚洲综合第一区 | 日本黄色播放器 | 亚洲色图欧美色 | 老色批永久免费网站www | 精品久久久久久久久久久 | 18做爰免费视频网站 | 婷婷亚洲综合 | 在线观看福利片 | 中国黄色a级| 人妖一区 | 日韩av在线一区 | 久久露脸国语精品国产91 | 污污内射久久一区二区欧美日韩 | 国产精品100| 免费看国产视频 | 午夜视频在线观看一区二区 | 影音先锋亚洲一区 | 国产又粗又猛又爽又黄的视频在线观看动漫 | 中文字幕精品久久久 | 日韩两性视频 | 亚洲视频二 | 日韩欧美黄| 四虎在线观看视频 | 老牛影视一区二区三区 | 国产免费黄色av | 影音先锋在线看片资源 | 公车激情云雨小说 | 国产一二三区精品 | 中文在线字幕 | 91偷拍精品一区二区三区 | 久久精品大片 | 成人av一区二区在线观看 | 久久久久久电影 | 91麻豆精品国产91久久久久久 | 开心激情久久 | 伊人久久一区 | 久久综合日本 | 日韩网站免费观看 | 欧美日韩不卡一区二区三区 | 中文字幕一区二区久久人妻 | 欧美色图另类 | 美女被男生免费视频 | av黄色小说 | 爆乳熟妇一区二区三区 | 在线黄色大片 | 日韩一级精品 | 婷婷导航| 动漫毛片 | 国产a级一级片 | 国产欧美日韩激情 | 天天操天天操天天干 | 天天操夜夜拍 | 美女精品久久久 | 操处女逼视频 | 日本美女日批视频 | 午夜成人鲁丝片午夜精品 | 亚洲成熟少妇视频在线观看 | 在线看成人av | 日日拍拍| www.四色| 天天视频入口 | 欧美777| 国产精品久久九九 | 91丝袜在线| 日本亚洲一区二区三区 | 四虎影视www在线播放 | 野花国产精品入口 |