链接:

https://vjudge.net/problem/LightOJ-1226

题意:

OUM is a one unit machine which processes jobs. Since it can't handle heavyweight jobs; jobs needs to be partitioned into units. Initially, all the job information and unit partitions are given as input. Then the machine allocates necessary time slots. And in each time slot it asks the user for the name of the job to be processed. After getting the name; the machine determines the next unprocessed unit of that job and processes that unit in that slot. If there is no such unit, the machine crashes. A job is said to be complete if all the units of that job are complete.

For example, let J1 and J2 be two jobs each having 2 units. So, OUM will create 4 time slots. Now the user can give J1 J2 J2 J1 as input. That means it completes the 1st unit of J1 in time slot 1 and then completes the 1st unit of J2 in time slot 2. After that it completes the 2nd unit of J2 and 2nd unit of J1 in time slots 3 and 4 respectively. But if the user gives J1 J1 J2 J1 as input, the machine crashes in time slot 4 since it tries to process 3rd unit of J1 which is not available.

Now, Sam is the owner of a software firm named ACM and he has n jobs to complete using OUM. He wants to complete Jobi before Jobi+1 where 1 ≤ i < n. Now he wants to know the total number of ways he can complete these jobs without crashing the OUM. He assigned you for this task. Two ways are different if at tth slot one processed a unit of Jobi and another processed a unit of Jobj where i ≠ j. For the example above, there are three ways:

J1 J1 J2 J2

J1 J2 J1 J2

J2 J1 J1 J2

思路:

考虑对前面放好了i个,下一个只要把一个放在最后,其他的放在前面任意组合即可。

得到第i个能放的方法\(C_{a[i]-1+sum}^{sum}\)sum为已经放了的个数

代码:

// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10; LL Fac[MAXN];
int a[MAXN], n; LL PowMod(LL a, LL b, LL p)
{
LL res = 1;
while(b)
{
if (b&1)
res = res*a%p;
a = a*a%p;
b >>= 1;
}
return res;
} LL ExGcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1, y = 0;
return a;
}
LL d = ExGcd(b, a%b, x, y);
LL tmp = x;
x = y;
y = tmp-(a/b)*y;
return d;
} LL GetInv(LL a, LL p)
{
LL x, y;
LL d = ExGcd(a, p, x, y);
if (d == 1)
return (x%p+p)%p;
else
return -1;
// return PowMod(a, p-2, p);
} LL C(LL a, LL b)
{
if (a < b)
return 0;
if (a == b)
return 1;
return (Fac[a]*GetInv(Fac[a-b]*Fac[b]%MOD, MOD))%MOD;
} LL Lucas(LL a, LL b)
{
if (b == 0)
return 1;
return C(a%MOD, b%MOD)*Lucas(a/MOD, b/MOD)%MOD;
} void Init()
{
Fac[0] = 1;
Fac[1] = 1;
Fac[2] = 2;
for (int i = 3;i < MAXN;i++)
Fac[i] = Fac[i-1]*i%MOD;
} int main()
{
// freopen("test.in", "r", stdin);
Init();
int t, cas = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cas);
scanf("%d", &n);
for (int i = 1;i <= n;i++)
scanf("%d", &a[i]);
LL ans = 1, sum = 0;
for (int i = 1;i <= n;i++)
{
ans = ans*C(a[i]-1+sum, sum)%MOD;
sum += a[i];
}
printf(" %lld\n", ans);
} return 0;
}

最新文章

  1. 微软要如何击败Salesforce?Office365、Azure、Dynamics365 全面布局AI | 双语
  2. Hibernate组件和关联映射
  3. 无阻塞加载js,防止因js加载不了影响页面显示
  4. 【转】(笔记)CANopen协议【CANFestival】移植方法
  5. asp.net中验证控件的使用方法
  6. 如何编译spring源码,并导入到eclipse中
  7. centos7重启rsyslog服务|centos7重启syslog服务
  8. 0. WP8.1学习笔记
  9. ADB工具 获取ROOT权限及复制文件方法
  10. System.Data.SqlClient.SqlError: 对文件……的目录查找失败[转]
  11. Easyui Datagrid rownumbers行号四位、五位显示不完全的解决办法
  12. osg
  13. mac系统奔溃无法启动时,如何备份重要资料
  14. Android 性能优化之减少UI过度绘制
  15. 用java 集合和映射实现文章的单词数目统计
  16. 力扣(LeetCode)561. 数组拆分 I
  17. centos7.4 可远程可视化桌面安装
  18. Mongodb 无法启动 windows Mongodb 无法启动 couldn&#39;t connect to server
  19. c#中的模态对话框和非模态对话框
  20. linux之ls、ll

热门文章

  1. python爬虫scrapy(一)
  2. 不一样的go语言-athens源码概览
  3. docker容器与主机之间的文件复制
  4. open_vPGPv
  5. javascript, 元素 页面 简单碰撞
  6. 使用vue-cookies
  7. mysql 设置局域网内可访问
  8. Winmanager,NERDTree和MiniBufExplorer
  9. 小程序canvas绘制倒计时
  10. Anaconda-Jupyter notebook 如何安装 nbextensions