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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

*【ZOJ - 3604】Tunnel Network (Cayley定理,purfer数列,无根树定理,构造,结论,或dp)

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 *【ZOJ - 3604】Tunnel Network (Cayley定理,purfer数列,无根树定理,构造,结论,或dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Country Far-Far-Away is a big country with?N?cities. But it is now under a civil war. The rebel uses the ancient tunnel network which connects all?N?cities with?N-1 inter-city tunnels for transportation. The government army want to destroy these tunnels one by one. After several months fighting, some tunnels have been destoryed. According to the intel, the tunnel network have excatly?S?connected components now. And what government army further knows is that city 1, 2, ... ,?S?belong to each of the?S?connected components. Since the government have little knowledge about the remaining tunnels, they ask you to calculate the number of possible networks of remaining tunnels.

Input

There are multiple test cases. The first line of input contains an integer?T?(T?≤ 500) indicating the number of test cases. Then?T?test cases follow.

Each case contains one line containing two integer?N?(2 ≤?N?≤ 2000) and?S?(2 ≤?S≤ N), as described above.

Output

The number of possible networks now. Since the number might be very large, you should output the answer after modulo 1000000007.

Sample Input

4 3 2 4 2 5 3 100 50

Sample Output

2 8 15 113366355

解題報告:

?且不說會不會T的問題,這個思路應該是沒錯的,但是只能過小樣例,過不了大樣例,不知道為什么。

?

AC代碼:

#include<bits/stdc++.h>using namespace std; typedef long long ll;const int mod=1e9+7;int main() {int T;scanf("%d",&T);while(T--) {ll n,s;scanf("%lld %lld",&n,&s);ll ans=s;for(ll i=1; i<n-s; i++) {ans=(ans*n)%mod;}if(n==s)ans=1;printf("%lld\n",ans);}return 0; }

WA代碼:

#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 using namespace std; const int MAX = 2e5 + 5; const ll mod = 1000000007; int n,s; ll C[2005][2005]; ll dp[2005][2005]; ll qpow(ll a,ll k) {if(k<=0) return 1;ll res = 1;while(k) {if(k&1) res = (res * a) % mod;a=(a*a)%mod;k>>=1;}return res; } void init() {C[0][0] = 1;for(int i = 1; i<=2002; i++) {C[i][0] = 1;for(int j = 1; j<=2002; j++) {C[i][j] = C[i-1][j] + C[i-1][j-1];}} } int main() {init();int t;cin>>t; // dp[i][j]代表前i個集合中放入了j個點的方案數。while(t--) {scanf("%d%d",&n,&s);memset(dp,0,sizeof dp);dp[0][0]=1;for(int i = 0; i<=n-s; i++) {dp[1][i] = (C[n-s][i]*qpow(i+1,i-1))%mod;}for(int i = 2; i<=s; i++) {for(int j = 0; j<=n-s; j++) {for(int k = 0; k<=j; k++) {dp[i][j] = (dp[i][j] + C[n-s-(j-k)][k] * dp[i-1][j-k]*qpow(k+1,k-1))%mod;}}}ll ans = dp[s][n-s]; // for(int i = 1; i<=n-s; i++) { // ans = (ans + dp[s][i])%mod; // }printf("%lld\n",ans);}return 0 ; } /* 100 4 1*/

https://blog.csdn.net/qq_36424540/article/details/80043433

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的*【ZOJ - 3604】Tunnel Network (Cayley定理,purfer数列,无根树定理,构造,结论,或dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

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