Topcoder SRM661 ColorfulLineGraphs
2015-06-15 00:17
537 查看
Problem Statement | ||||||||||||
Bob is going to create a graph with N nodes. The graph will be constructed in two steps. First, Bob will take N isolated vertices, label them 1 through N and color each of them using one of K colors. Then, Bob will add some directed edges to the graph. For each i between 2 and N, inclusive, Bob may choose a single value j < i such that the nodes i and j have different colors. If he does, he will add the edge from i to j to his graph. Note that Bob may choose not to add any edge from node i, even if there are some valid choices of j. Two graphs are considered the same if they have the same node colors and the same set of edges. You are given the long longs N and K. You are also given an int M. Compute and return the number of different graphs Bob may construct, modulo M. | ||||||||||||
Definition | ||||||||||||
| ||||||||||||
Limits | ||||||||||||
| ||||||||||||
Constraints | ||||||||||||
- | N will be between 1 and 1,000,000,000,000 (10^12), inclusive. | |||||||||||
- | K will be between 1 and 1,000,000,000,000 (10^12), inclusive. | |||||||||||
- | M will be between 2 and 1,000,000 (10^6), inclusive. | |||||||||||
Examples | ||||||||||||
0) | ||||||||||||
|
只需要在不考虑模数的情况下,推出公式:
再考虑模数的情况,借住快速幂和模的特性来很简单的求出答案。
反思:很多时候想复杂了。但也有很多情况是因为自己没有足够的能力和经验。
还是多做一些比赛吧。
相关文章推荐
- zoj3549 快速幂
- Codevs 1250、1732 矩阵 快速幂
- 蓝桥练习系统 历届试题 公式求值
- 矩阵快速幂求斐波那契通项(矩阵乘法优化线性递推式)
- poj3744 Scout YYF I
- 快速幂 小明系列故事——师兄帮帮忙
- 【学习笔记】快速幂
- [HDU4602]Partition
- hdu - 4602 《Partition》
- 快速幂
- 递推数列
- Wikioi P3285 转圈游戏
- POJ 3696 : The Luckiest number - 欧拉函数,快速幂[数论好题]
- POJ 3012 : A Number from Yanghui Triangle - 快速幂;推公式
- POJ 1001 高精度实数相乘与快速幂
- 神逻辑各种快速幂
- Codeforces 359C Prime Number (数学+快速幂)
- FZU 1759 Super A^B mod C (快速幂+指数循环节)
- FZU 1752 A^B mod C (快速幂)
- uva 10006 Carmichael Numbers