• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

codeforces57CArray(简单排列组合)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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





 1 #include <stdio.h>
 2 const long long mo = 1000000007;
 3 typedef long long ll;
 4 ll cc[200000];
 5 
 6 ll ext_gcd(ll a,ll b,ll &x,ll &y)
 7 {
 8     if(b==0){x=1;y=0;return a;}
 9     ll d=ext_gcd(b,a%b,x,y),t;
10     t=x;x=y;y=t-a/b*y;
11     return d;
12 }
13 ll inv(int a,int mo)
14 {
15     ll x,y,dx,g;
16     g=ext_gcd(a,mo,x,y);
17     dx=mo/g;
18     return (x%dx+dx)%dx;
19 }
20 int main()
21 {
22     ll n, i;
23     for (i = 1; i <= 100000; i++)
24         cc[i] = inv(i, mo);
25     scanf("%lld", &n);
26     ll hh;
27     ll ans;
28     hh = 2 * n - 1;
29     ans = 1;
30     for (i = 1; i <= n; i++,hh--)
31         ans = ans * hh %mo* cc[i] % mo;//保险点,宁可多mod一下的!! 
32     ans = (2 * ans - n + mo) % mo;
33     printf("%lld\n", ans);
34     return 0;
35 }
View Code

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
对C#中键盘响应事件的理解。发布时间:2022-07-13
下一篇:
C10K问题探讨发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap