CSUOJ 1525 Algebraic Teamwork
Problem A
Algebraic Teamwork
The great pioneers of group theory and linear algebra want to cooperate and join their theories. In group theory, permutations – also known as bijective functions – play an important role. For a finite set A, a function σ : A → A is called a permutation of A if and only if there is some function ρ : A → A with σ(ρ(a)) = a and ρ(σ(a)) = a for all a ∈ A.
The other half of the new team – the experts on linear algebra – deal a lot with idempotent functions. They appear as projections when computing shadows in 3D games or as closure operators like the transitive closure, just to name a few examples. A function p : A → A is called idempotent if and only if p(p(a)) = p(a) for all a ∈ A.
To continue with their joined research, they need your help. The team is interested in non-idempotent permutations of a given finite set A. As a first step, they discovered that the result only depends on the set’s size. For a concrete size 1 ≤ n ≤ 105, they want you to compute the number of permutations on a set of cardinality n that are not idempotent.
Input
The input starts with the number t ≤ 100 of test cases. Then t lines follow, each containing the set’s size 1 ≤ n ≤ 105.
Output
Output one line for every test case containing the number modulo 1000000007 = (109 + 7) of non-idempotent permutations on a set of cardinality n.
Sample Input |
Sample Output |
3 1 2 2171 |
0 1 6425 |
解题:n!-1
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = ;
const int md = 1e9+;
LL d[maxn];
int main(){
d[] = ;
for(int i = ; i < maxn; ++i)
d[i] = (i%md*d[i-])%md;
int x,ks;
scanf("%d",&ks);
while(ks--){
scanf("%d",&x);
printf("%lld\n",(d[x]+md-)%md);
}
return ;
}
CSUOJ 1525 Algebraic Teamwork的更多相关文章
- Teamwork[HDU4494]
Teamwork Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
- NBUT 1525 Cow Xor(01字典树+前缀思想)
[1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...
- 九度oj 1525 子串逆序打印
原题链接:http://ac.jobdu.com/problem.php?pid=1525 字符串简单题,注意开有结尾有空格的情况否则pe or wa #include<algorithm> ...
- (博弈论)hdoj 1525 Euclid's Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525 题目大意:Stan和Ollie在玩一个游戏,a和b两个数字,每次可以选择较大的数减去较小的数的若 ...
- hdu 4494 Teamwork 最小费用最大流
Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 ...
- csuoj 1354: Distinct Subsequences
这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...
- 九度OJ 1525 子串逆序打印 -- 2012年Google校园招聘笔试题目
题目地址:http://ac.jobdu.com/problem.php?pid=1525 题目描述: 小明手中有很多字符串卡片,每个字符串中都包含有多个连续的空格,而且这些卡片在印刷的过程中将字符串 ...
- 【HDOJ】1525 Euclid's Game
自己想明白的第一道博弈.首先a==b的时候肯定是先手赢: 然后当a>=2*b时,不妨假设a=nb+k, k<b,因此,不论后续怎么博弈,一定可以出现a=k, b=b的情况.因此,无论这个局 ...
随机推荐
- HTML5 内联 SVG
SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用于定义用于网络的基于矢量的图形 SVG 使用 XML 格式定义图形 SVG 图像在放大或改变尺寸的情况下其图形 ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- angularjs 标签指令
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- hpuoj--校赛--送给新生的礼物(水题)
问题 A: 感恩节KK专场--送给新生的礼物 时间限制: 1 Sec 内存限制: 128 MB 提交: 631 解决: 187 [提交][状态][讨论版] 题目描述 学长KK要送给学弟学妹们礼物, ...
- OWIN是Open Web Server Interface for .NET
http://owin.org/ Servers and Hosts Katana Nowin Suave Frameworks Jasper Nancy SignalR WebApi WebShar ...
- 51Nod 1433 0和5(数论)
小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5.小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数.使得这个数尽可能大,而且可以被90整除. 注意: 1.这个数没有前 ...
- php基础:implode()函数 和exlplode函数
1implode() 函数返回一个由数组元素组合成的字符串. 注释:implode() 函数接受两种参数顺序.但是由于历史原因,explode() 是不行的,您必须保证 separator 参数在 s ...
- 三维偏序(陌上花开) CDQ分治
十分巧妙. Code: #include <cstdio> #include <algorithm> #include <cstring> #define setI ...
- 洛谷 P2542 [AHOI2005]航线规划 树链剖分_线段树_时光倒流_离线
Code: #include <map> #include <cstdio> #include <algorithm> #include <cstring&g ...
- PHP 数组转字符串,字符串转数组
explode将字符串分割为数组: $str = explode( ',',$str); 第一个参数为字符串的分界符,例如1,2,3,4. 第二个是需要分割的数组 分割后就是 array( 1 , 2 ...