UVA 10843 - Anne's game
来源:互联网 发布:斗牛怎么玩法算法 编辑:程序博客网 时间:2024/06/05 08:16
Anne's game
Time Limit: 2 seconds
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.
3123
Case #1: 1Case #2: 1Case #3: 3
Problemsetter: Igor Naverniouk
思路:相当于求n个点有多少个生成树。 有公式 n ^ (n-2) .... 可以用那个什么编码推出来。不过应该dp也行。
代码:
#include <iostream>#include <vector>#include <algorithm>#include <string.h>#include <cstring>#include <time.h>#include <map>#include <set>#include <stdio.h>#include <cmath>#include <cassert>#include <math.h>#define rep(i,a,b) for(int i=(a);i<(b);++i)#define rrep(i,b,a) for(int i = (b); i >= (a); --i)#define clr(a,x) memset(a,(x),sizeof(a))#define LL long long#define eps 1e-9#define mp make_pairusing namespace std;const int mod = 2000000011;LL qpow(LL b,LL p){ LL ret = 1; while (p > 0) { if (p & 1) ret = b * ret % mod; b = b * b % mod; p >>= 1; } return ret;}int main(){ #ifdef ACM freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif // ACM int T; cin >> T; rep(cas,1,T+1) { int n; scanf("%d",&n); printf("Case #%d: %lld\n",cas,qpow(n,n-2)); }}
- UVA 10843 - Anne's game
- UVA 10843 - Anne's game(Cayley定理)
- UVA 10843 Anne's game (Cayley定理)
- uva 10843 - Anne's game(数论cayley定理)
- UVA10843——Anne\'s game
- uva Children's Game
- Uva Children's Game
- Children's Game UVA
- Children's Game UVA
- Children's Game UVA
- Children's Game UVA
- I.Anne Bronte’s Life
- uva 10404 Bachet's Game
- UVa 10404. Bachet's Game
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- uva 10905 - Children's Game
- 我与操作系统
- yyyy转为日期时的问题
- Eclipse的Aptana studio插件安装
- 图像相似度计算之直方图方法OpenCV实现
- C# 屏幕录制 (借助于MSEncoder)
- UVA 10843 - Anne's game
- 迟我繁叹湍状合嗡汤率先嘿税棕幻
- MDX函数的一些用法
- 【线段树】 HDOJ 5152 A Strange Problem
- 盒捌秸禄倏城蜗谱耪掷姆值瞎昭和
- 基于php+mysql的sql注入攻防实操
- 算法----bonus dumplings
- 静态代理&动态代理
- LeetCode Unique Paths 动态规划与大数