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的情况.因此,无论这个局 ...
随机推荐
- Git(三):加入与提交
在这一节.接着使用上一节的代码样例往下讲,http://blog.csdn.net/troy__/article/details/39806245. 加入文件到暂存区 加入新文件和改动版本 ...
- Android笔记---点击事件的四种写法
Android 点击事件的四种写法: 1. 以内部类的形式实现 OnClickListener 接口.定义点击事件 class MainActivity extents Activity{ // .. ...
- 最短路径----SPFA算法
求最短路径的算法有许多种,除了排序外,恐怕是ACM界中解决同一类问题算法最多的了.最熟悉的无疑是Dijkstra,接着是Bellman-Ford,它们都可以求出由一个源点向其他各点的最短路径:如果我们 ...
- [JZOJ4272] [NOIP2015模拟10.28B组] 序章-弗兰德的秘密 解题报告(树形DP)
Description 背景介绍弗兰德,我不知道这个地方对我意味着什么.这里是一切开始的地方.3年前,还是个什么都没见过的少年,来到弗兰德的树下,走进了封闭的密室,扭动的封尘已久机关,在石板上知道了这 ...
- Anaconda升级
Anaconda是可以进行升级的, 这样就省的重装一遍python全家桶了, 比如: conda update conda conda install anaconda=2018.12 就可以 ...
- SharePoint 修改完或制作完一定要发布
设置了匿名访问但是网站就是需要登录,找了很多问题. 首先想到的映射问题,然后努力检查,最后把代码删掉,然后把站删掉,最后测试出来问题. 点击上方[网站设置] 把修改过的文件发布. 母版也和布局页 一定 ...
- LOJ #109. 并查集
内存限制:256 MiB时间限制:2000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论 1 测试数据 题目描述 这是一道模板题. 维护一个 nnn 点 ...
- AngularJs轻松入门(三)MVC架构
MVC应用程序架构最早于1970年起源于Smalltalk语言,后来在桌面应用程序开发中使用较为广泛,如今在WEB开发中也非常流行.MVC的核心思想是將数据的管理(Model).业务逻辑控制(Cont ...
- 使用regasm注册.net com组件出现不是有效的.net程序集的解决办法
作者:朱金灿 来源:http://blog.csdn.net/clever101 在电脑上装有VS 2008和VS 2010.使用VS 2010编写了一个C# com组件:MyCom(基于.net f ...
- 基于Struts2+MySQL的多表出差明细表单
下载地址:http://download.csdn.net/detail/qq_33599520/9790629 项目结构: UserAction package com.mstf.action; i ...