codeforces 57 C Array(简单排列组合)
2 seconds
256 megabytes
standard input
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.
The single line contains an integer n which is the size of the array (1 ≤ n ≤ 105).
You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007.
2
4
3
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(简单排列组合)的更多相关文章
- Codeforces Gym 100187D D. Holidays 排列组合
D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...
- Codeforces 991E. Bus Number (DFS+排列组合)
解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...
- CodeForces - 817B(分类讨论 + 排列组合)
题目链接 思路如下 这一题是:最菜的队伍只有三个人组成,我们只需对排序后的数组的 前三个元素进行分类讨论即可: a[3] != a[2] && a[3] != ar[1] a[3] = ...
- BZOJ 1008 [HNOI2008]越狱 (简单排列组合 + 快速幂)
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 10503 Solved: 4558[Submit][Status ...
- js 排列 组合 的一个简单例子
最近工作项目需要用到js排列组合,于是就写了一个简单的demo. 前几天在网上找到一个写全排列A(n,n)的code感觉还可以,于是贴出来了, 排列的实现方式: 全排列主要用到的是递归和数组的插入 比 ...
- 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 ...
- SPOJ - AMR11H Array Diversity (水题排列组合或容斥)
题意:给定一个序列,让你求两种数,一个是求一个子序列,包含最大值和最小值,再就是求一个子集包含最大值和最小值. 析:求子序列,从前往记录一下最大值和最小值的位置,然后从前往后扫一遍,每个位置求一下数目 ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
随机推荐
- git本地分支推送到远程分支
1.创建的创建和初始化 创建git仓库可以在远端创建一个仓库, 然后check到本地,在本地的文件里创建工程文件,然后提交 也可以将本地现有的工程和远端的空仓库关联 本地创建了一个工程 iOSDemo ...
- Linux下服务器开发的必要准备
一.Windows下安装Xshell 二.Linux开启SSH 可以先查询有没有SSH服务 sudo ps -e |grep ssh 没有安装SSH的服务器 sudo apt-get install ...
- 【机器学习速成宝典】模型篇02线性回归【LR】(Python版)
目录 什么是线性回归 最小二乘法 一元线性回归 多元线性回归 什么是规范化 Python代码(sklearn库) 什么是线性回归(Linear regression) 引例 假设某地区租房价格只与房屋 ...
- 百度编辑器ueditor上传图片失败,显示上传错误,实际上图片已经传到服务器或者本地
报错,上传失败,图片没有显示,且调试response没有信息,但是图片已经上传到了本地 这个问题是因为ueditor里面的Upload.class.php里面__construct()方法里面的ico ...
- k8s 添加ingress 暴露服务
vim file.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: pgadmin labels: k8s-app: ...
- 阶段2 JavaWeb+黑马旅游网_15-Maven基础_第5节 使用骨架创建maven的java工程_18maven的java工程取mysql数据库
使用maven创建ava功能,然后读取数据库做一个测试. 我们做的持久层,没有和页面有交互,只做一个java工程就可以了 创建的是java工程,用不用骨架都可以.这里不使用骨架,直接next 直接fi ...
- Selenium学习之==>WebDriver驱动对照表
转自www.imdsx.cn 1.Chrome 对于chrome浏览器,有时候会有闪退的情况,也许是版本冲突的问题,我们要对照着这个表来对照查看是不是webdriver和chrome版本不对. chr ...
- oracle rman catalog--ORA-01580: error creating control backup file
在测试rman catalog时,错误的设置了snapshot路径,报错 RMAN> show snapshot controlfile name; RMAN configuration par ...
- html5获取位置信息,h5获取位置信息
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- CSS——插入形式 基本格式 常见css代码
常见css代码 无下划线链接 字体颜色 + 左边距 背景颜色 字体.字体颜色.大小 文本对齐方式[取代了<center>]