Codeforces Beta Round 37
D
课程表
Lesson Timetable
Codeforces
2300
原题
← CE →

课程表AI (CI翻译)

When Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long corridor with $*M*$ classrooms numbered from $1$ to $*M*$, situated along it.

当 Petya 不玩电脑游戏时,他会去上大学课程。Petya 所在系每天的课程由两节连堂课组成。上课的楼层是一条长走廊,沿走廊有 $*M*$ 间教室,编号为 $1$ 到 $*M*$。AI (CI翻译)

All the students of Petya’s year are divided into $*N*$ groups. Petya has noticed recently that these groups’ timetable has the following peculiarity: the number of the classroom where the first lesson of a group takes place does not exceed the number of the classroom where the second lesson of this group takes place.

Petya 所在年级的学生被分成了 $*N*$ 个小组。最近,Petya 注意到这些小组的课程表有一个特点:每个小组第一节课所在教室的编号不大于第二节课所在教室的编号。AI (CI翻译)

Once Petya decided to count the number of ways in which one can make a lesson timetable for all these groups. The timetable is a set of $2*N*$ numbers: for each group the number of the rooms where the first and the second lessons take place. Unfortunately, he quickly lost the track of his calculations and decided to count only the timetables that satisfy the following conditions:

有一天,Petya 决定统计所有小组课程表的可能数量。课程表由 $2*N*$ 个数构成:对每个小组,记录其第一节课和第二节课所在教室的编号。遗憾的是,他很快就算乱了,于是决定只统计满足以下条件的课程表:AI (CI翻译)

  1. On the first lesson in classroom $*i*$ exactly $*X*_{*i*}$ groups must be present.
  1. 第一节课时,教室 $*i*$ 中恰好有 $*X*_{*i*}$ 个小组上课。
AI (CI翻译)
  1. In classroom $*i*$ no more than $*Y*_{*i*}$ groups may be placed.
  1. 教室 $*i*$ 中同时上课的小组数不超过 $*Y*_{*i*}$。
AI (CI翻译)

Help Petya count the number of timetables satisfying all those conditionsю As there can be a lot of such timetables, output modulo $10^{9} + 7$.

请帮助 Petya 统计满足所有条件的课程表数量。由于答案可能很大,请对 $10^{9} + 7$ 取模后输出。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains one integer $*M*$ ($1 ≤ *M* ≤ 100$) — the number of classrooms.

第一行包含一个整数 $*M*$($1 ≤ *M* ≤ 100$),表示教室数量。AI (CI翻译)

The second line contains $*M*$ space-separated integers — $*X*_{*i*}$ ($0 ≤ *X*_{*i*} ≤ 100$) the amount of groups present in classroom $*i*$ during the first lesson.

第二行包含 $*M*$ 个以空格分隔的整数 $*X*_{*i*}$($0 ≤ *X*_{*i*} ≤ 100$),表示第一节课时在教室 $*i*$ 上课的小组数。AI (CI翻译)

The third line contains $*M*$ space-separated integers — $*Y*_{*i*}$ ($0 ≤ *Y*_{*i*} ≤ 100$) the maximal amount of groups that can be present in classroom $*i*$ at the same time.

第三行包含 $*M*$ 个以空格分隔的整数 $*Y*_{*i*}$($0 ≤ *Y*_{*i*} ≤ 100$),表示同一时间可在教室 $*i*$ 上课的小组数上限。AI (CI翻译)

It is guaranteed that all the $*X*_{*i*} ≤ *Y*_{*i*}$, and that the sum of all the $*X*_{*i*}$ is positive and does not exceed $1000$.

保证对于所有 $i$,均有 $*X*_{*i*} ≤ *Y*_{*i*}$,且所有 $*X*_{*i*}$ 之和为正数且不超过 $1000$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

In the single line output the answer to the problem modulo $10^{9} + 7$.

单行输出问题的答案对 $10^{9} + 7$ 取模后的结果。AI (CI翻译)

Note

说明

AI (CI翻译)

In the second sample test the first and the second lessons of each group must take place in the same classroom, that’s why the timetables will only be different in the rearrangement of the classrooms’ numbers for each group, e.g. $3! = 6$.

在第二个样例中,每个小组的第一节课和第二节课都必须在同一间教室上,因此不同的课程表只在各组对应的教室编号排列上有所区别,例如 $3! = 6$。AI (CI翻译)

样例

Input #1
3
1 1 1
1 2 3
Output #1
36
InputCopy OutputCopy
Input #2
3
1 1 1
1 1 1
Output #2
6
InputCopy OutputCopy
题目信息
题号
37D
时间限制
1 s
内存限制
256 MB
标签
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。