Problem J Permutation Counting
Dexter considers a permutation of first N natural numbers good if it doesn't have x and x+1 appearing consecutively, where (1 ≤ x < N)  For example, for N=3 , all goodpermutations are:
1. {1, 3, 2}
2.{2, 1, 3}
3.{3, 2, 1}
Input
Input starts with an integer T (≤ 10000 , denoting the number of test cases.Each
case starts with a line containing an integer N (1 ≤ N ≤ 106)
.
Output
For each case, print the case number and the number ofgoodpermutations
modulo1000 000 007
.
Sample Input
Output for Sample Input
3
2
3
5
Case 1: 1
Case 2: 3
Case 3: 53

 #include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include<climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 1000005
#define MOD 1000000007
LL ans[MAXN],tmp[MAXN];
void init()
{
ans[]=;ans[]=;
for (int i=;i<MAXN;i++)
{
ans[i]=((i-)*ans[i-])+(i-)*ans[i-];
ans[i]%=MOD;
}
}
int main()
{
init();
int T;int kase=;
scanf("%d",&T);
while (T--)
{
int N;
scanf("%d",&N);
printf("Case %d: %lld\n",kase++,ans[N]);
}
return ;
}
 

最新文章

  1. 修复 Windows7 资源管理器左侧收藏夹无法展开问题
  2. 2016 daily
  3. Hibernate(Control)
  4. struts2中的OGNL详解
  5. ORACLE 自治事物
  6. 【Oracle】ORA-28000: the account is locked-的解决办法
  7. [bzoj 3687]简单题 bitset的运用
  8. Struts2中的链接标签 &lt;s:url&gt;和&lt;s:a&gt;---在action中获取jsp表单提交的参数(转)
  9. 实用chrome插件
  10. EC读书笔记系列之14:条款26、27、28、29、30、31
  11. PHP中include与require的特点和区别说明
  12. 深入学习c++(虚函数遇到析构函数就退化了)
  13. jquery实现本地图片上传预览和限流处理
  14. git笔记(2)-常见命令的使用(详解待续)
  15. luogu P1816 【忠诚】
  16. 「TJOI2015」线性代数 解题报告
  17. mysql的并发控制
  18. LeetCode OJ 94. Binary Tree Inorder Traversal
  19. Windows编译Opencv
  20. [Linux]《鸟哥的私房菜》笔记 (缓慢更新)

热门文章

  1. Nginx中worker_connections的问题
  2. java基础55 UDP通讯协议和TCP通讯协议
  3. window时间同步机制的简单介绍
  4. 读书笔记--C陷阱与缺陷(六)
  5. HDU 2874 Connections between cities(LCA(离线、在线)求树上距离+森林)
  6. Oracle学习笔记:实现select top N的方法
  7. 2016-2017-2 20155309 南皓芯《java程序设计》第八周学习总结
  8. entityframework导航属性筛选
  9. C#重写ToString
  10. java异常查看利器之使用 jvmti 的Callback_JVMTI_EVENT_EXCEPTION 事件查看异常