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. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game

    G: 要你去才Paul的年龄,Paul的年龄在1~n之间,你每猜一个Paul会告诉你,你猜的这个数和他年龄的gcd,问在最坏情况下最少要猜多少次. 题解: 什么是最坏情况,我们直到如果他的年龄是1的话 ...

  2. 微信小程序 API 数据缓存

    微信小程序 数据缓存 (类似于 cookie) wx.setStorage() 将数据存储在本地缓存中制定的 key 中.会覆盖掉原来该 key 对应的内容,数据存储生命周期跟小程序本身一致,即除用户 ...

  3. 一、基础篇--1.1Java基础-Exception、Error、RuntimeException与一般异常有何异同

    Throwable.Error.Exception.RuntimeException 关系如下类图所示: Throwable: Throwable类是java语言中所有错误或者异常的超类.它的两个子类 ...

  4. CANopen的相关学习

    CANopen是一种架构在控制局域网路(Controller Area Network, CAN)上的高层通讯协定,包括通讯子协定及设备子协定常在嵌入式系统中使用,也是工业控制常用到的一种现场总线. ...

  5. Matlab——表达式 阵列与矩阵的创建

    表达式 指令过长: 如果一个指令过长可以在结尾加上... 下一行继续写指令即可 若不想每次都显示运算结果,只需在运算式最後加上分号(:)即可 注释 基本的算术运算有: 加 (+).减 (-).乘 (* ...

  6. html的标签规范

    if/else标签{ % if condition1 %} ... display 1{ % elif conditon2 %} ... display 2{ % else % } ... displ ...

  7. python实例1-找质数/素数

    质数定义:质数(prime number)又称素数.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 示例解决方案1 有很多方法可以解决这个问题,下面是一些例子:这是一个不同的功能分解 ...

  8. 重载Prometheus配置

    发送SIGHUP信号给应用程序的主进程: pid ‘’-1‘’是指“终端断线” 发送post请求给指定端点: curl -XPOST http://ip:9090/-/reload 对于此种方法要注意 ...

  9. Java实验报告(一)

    1.水仙花数 public class test1{ public static void main(String[] args){ for(int num=100;num<1000;num++ ...

  10. python爬取b站排行榜

    爬取b站排行榜并存到mysql中 目的 b站是我平时看得最多的一个网站,最近接到了一个爬虫的课设.首先要选择一个网站,并对其进行爬取,最后将该网站的数据存储并使其可视化. 网站的结构 目标网站:bil ...