编程介的小学生 2017-11-22 14:47 采纳率: 20.5%
浏览 756
已采纳

Three Eggache God

Problem Description
Alpheus has n monsters,their heights are A1,A2,A3....An. God Kufeng has n sons,their heights are 1,2,3....n.
One day, Our daredevil God Kufeng wants to challenge Alpheus. He sends his n sons to fight with Alpheus's n monsters ,the i-th son fighting with the i-th monster. During one challenge,if the i-th son's height is equal or greater than the i-th monster's height,the i-th son will get one score for his father,else,he'll get nothing.
Since Alpheus is strong enough to accept an infinity number of challenges,God Kufeng can challenge Alpheus again and again,but he has to change his son's order after every challenge,and the same permutation can not appear more than once.(that is,God Kufeng has n! times to challenge Alpheus).
Now,God Wu--the god of universe,wants to make things difficult to Kufeng.He has n sons too,their heights are W1,W2,W3....Wn(it is a permutation of 1,2,3.....n),God Wu said to Kufeng: Only when the lexicographic order of your sons' heights is bigger than my son's,you can challenge my lovely Alpheus!
Question:What is the total score God Kufeng can get?Output the answer mod 1000000007.
Note:
Alpheus will never change his monster's order,God Wu will never change his son's order.
For two permutation A and B,if Ai=Bi for all i(1<=i<=n),we say A=B.else,we get the smallest i that Ai!=Bi,if Ai>Bi,we say A's lexicographic order is bigger than B,otherwise,B is bigger than A.

Input
First,there is an integer T(T<=20),the number of test cases.
For every case,there are three lines.
The first line is an integer n(1<=n<=2000),the number of sons of God Kufeng.
The second line has n integers,W1,W2,W3.....Wn,the heights of God Wu's sons.(we guarantee that W1,W2,W3.....Wn is a permutation of 1,2,3....n).
The third line also has n integers, A1,A2,A3....An(1<=Ai<=n),the heights of Alpheus's monsters.

Output
For every test case,output one line,"Case #k: ans",where k is the case number,counting from 1,ans is the total score God Kufeng can get(mod 1000000007).

Sample Input
2
3
3 1 2
1 2 3
3
3 2 1
1 1 1

Sample Output
Case #1: 2
Case #2: 0

  • 写回答

1条回答

报告相同问题?

悬赏问题

  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出