time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of n, containing only integers from 1 to n. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions:

  • each elements, starting from the second one, is no more than the preceding one
  • each element, starting from the second one, is no less than the preceding one

Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last.

Input

The single line contains an integer n which is the size of the array (1 ≤ n ≤ 105).

Output

You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007.

Sample test(s)
input
2
output
4
input
3
output
17
 #include <stdio.h>
const long long mo = ;
typedef long long ll;
ll cc[]; ll ext_gcd(ll a,ll b,ll &x,ll &y)
{
if(b==){x=;y=;return a;}
ll d=ext_gcd(b,a%b,x,y),t;
t=x;x=y;y=t-a/b*y;
return d;
}
ll inv(int a,int mo)
{
ll x,y,dx,g;
g=ext_gcd(a,mo,x,y);
dx=mo/g;
return (x%dx+dx)%dx;
}
int main()
{
ll n, i;
for (i = ; i <= ; i++)
cc[i] = inv(i, mo);
scanf("%lld", &n);
ll hh;
ll ans;
hh = * n - ;
ans = ;
for (i = ; i <= n; i++,hh--)
ans = ans * hh %mo* cc[i] % mo;//保险点,宁可多mod一下的!!
ans = ( * ans - n + mo) % mo;
printf("%lld\n", ans);
return ;
}

codeforces 57 C Array(简单排列组合)的更多相关文章

  1. Codeforces Gym 100187D D. Holidays 排列组合

    D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...

  2. Codeforces 991E. Bus Number (DFS+排列组合)

    解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...

  3. CodeForces - 817B(分类讨论 + 排列组合)

    题目链接 思路如下 这一题是:最菜的队伍只有三个人组成,我们只需对排序后的数组的 前三个元素进行分类讨论即可: a[3] != a[2] && a[3] != ar[1] a[3] = ...

  4. BZOJ 1008 [HNOI2008]越狱 (简单排列组合 + 快速幂)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 10503  Solved: 4558[Submit][Status ...

  5. js 排列 组合 的一个简单例子

    最近工作项目需要用到js排列组合,于是就写了一个简单的demo. 前几天在网上找到一个写全排列A(n,n)的code感觉还可以,于是贴出来了, 排列的实现方式: 全排列主要用到的是递归和数组的插入 比 ...

  6. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  7. SPOJ - AMR11H Array Diversity (水题排列组合或容斥)

    题意:给定一个序列,让你求两种数,一个是求一个子序列,包含最大值和最小值,再就是求一个子集包含最大值和最小值. 析:求子序列,从前往记录一下最大值和最小值的位置,然后从前往后扫一遍,每个位置求一下数目 ...

  8. [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)

    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...

  9. [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)

    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...

随机推荐

  1. legend3---用Homestead配置后报错“No input file specified.”

    legend3---用Homestead配置后报错“No input file specified.” 一.总结 一句话总结: 自己项目上传到github的时候多增加了一层legend3的github ...

  2. Android NDK的生命周期JNI_OnLoad与JNI_OnUnload(转)

    摘要 NDK的生命周期 //当动态库被加载时这个函数被系统调用 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { LOGI ...

  3. leetcode-mid-design-297. Serialize and Deserialize Binary Tree¶-NO -??

    mycode 将list转换成树的时候没有思路 参考: deque 是双边队列(double-ended queue),具有队列和栈的性质,在 list 的基础上增加了移动.旋转和增删等 class ...

  4. DAY 7 上午

    一些图论的题目 BZOJ 3445 Roadblock 求出最短路,枚举每条边再跑一遍即可(科技为了我 代码: #include<bits/stdc++.h> using namespac ...

  5. 《ECMAScript6 入门》

    NVM Babel babel-core:提供 Babel 的 API,可以获得转码后的代码和抽象语法树. babel-polyfill:Babel 只能转换语法,如果想用类似 Promise.Gen ...

  6. python-接口开发flask模块(三)开发登陆接口

    #写一个login的接口,实现的功能是输入用户名和密码,如果数据库中有该用户,那么就去redis中插入 登陆产生的sign值插入redis中有效时间600s import flask import t ...

  7. 6.k8s.存储Volume.PV.PVC

    #Volume Volume 解决数据持久化和容器间共享数据 Kubernetes支持几十种类型的后端存储卷 #hostPath挂载实例,挂载Node节点/tmp/test-volume目录到容器/t ...

  8. cocos2dx基础篇(21) 进度条CCProgressTimer

    [3.x] (1)去掉 "CC" (2)CCProgressTimerType 改为强枚举 ProgressTimer::Type:: // RADIAL //扇形进度计时器 BA ...

  9. tensorflow学习之搭建最简单的神经网络

    这几天在B站看莫烦的视频,学习一波,给出视频地址:https://www.bilibili.com/video/av16001891/?p=22 先放出代码 #####搭建神经网络测试 def add ...

  10. seanborn使用函数regplot回归分析绘图

    可以用regplot(x, y, data)绘制回归图.data参数是DataFram类型,x是其中某一列列名,是即将绘制的图的x坐标,y是其中某一列,是图的y坐标 下面代码是对seaborn内置数据 ...