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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

UVA10843——Anne\'s game

發布時間:2023/11/30 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVA10843——Anne\'s game 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Lily: “Chantarelle was part of my exotic phase.”

Buffy: “It’s nice. It’s a mushroom.”

Lily: “It is? That’s really embarrassing.”

Buffy: “Well, it’s an exotic mushroom, if that’s any comfort.”

Joss Whedon, "Anne".

A little girl whose name is Anne Spetring likes to play the following game. She draws a circle on

paper. Then she draws another one and connects it to the first cicrle by a line. Then she draws another

and connects it to one of the first two circles by a line. She continues this way until she has n circles

drawn and each one connected to one of the previously drawn circles. Her circles never intersect and

lines never cross. Finally, she numbers the circles from 1 to n in some random order.

How many different pictures can she draw that contain exactly n circles? Two pictures are different

if one of them has a line connecting circle number i to circle number j, and the other picture does not.

Input

The first line of input gives the number of cases, N. N test cases follow. Each one is a line containing

n (0 < n ≤ 100).

Output

For each test case, output one line containing ‘Case #x:’ followed by X, where X is the remainder

after dividing the answer by 2000000011.

Sample Input

3

1

2

3

Sample Output

Case #1: 1

Case #2: 1

Case #3: 3

?

題意:題目說畫圈,實際上圈可以看成是點,然后就是求n個點,可以接連出多少種不同的生成樹的問題了!

?

思路:Caylay定理,網上能找到證明,結果為nn-2次方,然后利用快速二分冪求模去求解(以前總結的 快速二分冪求模)。


?code:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const int mod=2000000011;
int T,n;

ll big_mod(int a,int b) //關鍵實現函數,以前總結
{
ll ans=1,t=a;
while(b)
{
if(b&1) ans=ans*t%mod;
t=t*t%mod;
b>>=1;
}
return ans%mod;
}
int main()
{
scanf("%d",&T);
for (int ca=1;ca<=T;ca++)
{
int ans=1;
scanf("%d",&n);
if (n>1) ans=big_mod(n,n-2);
printf("Case #%d: %d\n",ca,ans);
}
}


總結

以上是生活随笔為你收集整理的UVA10843——Anne\'s game的全部內容,希望文章能夠幫你解決所遇到的問題。

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