HDU 4048 Zhuge Liang's Stone Sentinel Maze

Zhuge Liang‘s Stone Sentinel Maze

Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 385    Accepted Submission(s): 106

Problem Description


Zhuge Liang was a chancellor of the state of Shu Han during the Three Kingdoms period of Chinese history. He is often recognized as the greatest and most accomplished strategist of his era. He was so smart that his name also means “wise man” in Chinese.

One of Zhuge Liang’s achievements in legend is the Stone Sentinel Maze. It was an array of rocks and boulders built to defend against enemies. The formation was located on Yufu Shore by the Yangtze River near present-day Baidicheng, Chongqing, China, where supposed ruins of the array exist.

In chapter 84 of the historical novel Romance of the Three Kingdoms, as Lu Xun neared Baidicheng, he felt a strong enemy presence in the area and alerted his army to a possible ambush. He sent scouts ahead, who reported that the region was deserted except for some scattered piles of rocks. The bewildered Lu Xun asked a local, who told him that qi ("energy") started emerging from the area after Zhuge Liang arranged the rocks there. Lu Xun personally inspected the area and decided that the array was only a petty display of deception. Hence, Lu Xun led a few horsemen with him into the maze, and as he was about to exit, there was a strong gust of wind. At that moment, dust storms overshadowed the sky and the rocks appeared to become valleys; mountainous piles of dirt emerged and the roar of thunder rocked the skies while the waves of the nearby Yangtze River sounded like the clashing of swords and beating of war drums…

After the research on the Stone Sentinel Maze, scientists find some regulations. The rocks have m different kinds of weight (1<=m<=10,000). The weight of a rock is a positive integer not exceeding 10,000. There are n (3<=n<=100,000) rocks placed on a circle with equal spacing and the greatest common divisor of their weight is 1. They want to know in how many ways the rocks can be placed like that.

Notice:
1. Multiple rocks with the same weight can be placed on the circle.
2. If a solution will be the same as another one by rotation, these two solutions should be consider as the same.
3. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10,007.

Input

The input begins with a line containing an integer T, the number of test cases.
For each case, the first line begins with two integers --- the above mentioned m and n. Then m lines follow, each containing a positive integer representing rock weight. It is guaranteed that these m integers are different.

Output

For each case, output one integer in one line, representing the remainder of the number of ways when divided by 10,007.

Sample Input

2

2 3

2

3

3 3

6

10

15

Sample Output

2

2

Source

The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest

题意:给你m种石头子,每种无限多个,选出n个构成环,满足GCD(a1,a2,,,an)=1;

如果通过旋转相同,看成一种。

HDU 4048 Zhuge Liang's Stone Sentinel Maze

时间: 2024-10-12 17:28:41

HDU 4048 Zhuge Liang's Stone Sentinel Maze的相关文章

HDU 4772 Zhuge Liang&#39;s Password

Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous and smart military leader. His enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it was

HDU 4772 Zhuge Liang&#39;s Password 选择矩阵

本题需要使用选择矩阵的程序求解,这个和Leetcode上的一个程序是一样道理的.如果使用额外空间,那么是很容易做到的,这里不使用额外空间,直接使用到位操作,空间效率是O(1),这是个非常漂亮的到位旋转程序. 题意还是很重要,这次看错了一句话,就WA了一次: The maximum amount of cells which contains two equal numbers after overlapping, is the password. 这里是需要每次旋转之后求相同数字的最大值,而不是

hdu 4739 Zhuge Liang&#39;s Mines 随机化

Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4739 Description In the ancient three kingdom period, Zhuge Liang was the most famous and smartest military leader. His enemy was Shima Yi, who

HDU 4772 Zhuge Liang&#39;s Password (矩阵旋转)

Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 931    Accepted Submission(s): 641 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous

HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1404    Accepted Submission(s): 926 Problem Description In the anc

HDU 4772 Zhuge Liang&#39;s Password(模拟水)

HDU 4772 Zhuge Liang's Password 题目链接 题意:给定两张牌,可以旋转后重叠,重合后相同数字最多的是密码,求密码 思路:直接模拟记录最大值即可 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 35; int n; int a[N][N], b[N][N]; int solve() { int

hdu - 2216 Game III &amp;&amp; xtu 1187 Double Maze (两个点的普通bfs)

http://acm.hdu.edu.cn/showproblem.php?pid=2216 zjt和sara在同一个地图里,zjt要去寻找sara,zjt每移动一步sara就要往相反方向移动,如果他们相邻或者在同一个格子里就算相遇. 输出最少步数.注意zjt每次必须要有能移动的点才移动,否则不能移动,但是sara没有能移动的点的话可以呆着不动. 用结构体保存两个点和相应的步数作为一个状态,然后用哈希函数映射出每一个状态的的哈希值,放入set中,判重. 注意哈希函数的选取要确保不能重复. 1 #

HDU 5996:dingyeye loves stone(阶梯博弈)

http://acm.hdu.edu.cn/showproblem.php?pid=5996 题意:在一棵树上进行博弈,每次只能将当前的结点的石子放到父节点上,最后不能移动的输. 思路:比赛的时候想的是对于每一个深度为dep的结点,可以转化为dep堆同样的深度为1的结点,然后就不会了,忘了最后异或起来偶数可以抵消,相当于对方移动,我方也跟着移动对方上一个回合移动的石子,所以最后只要考虑深度为奇数的结点. 1 #include <cstdio> 2 #include <algorithm&

hdu 4739Zhuge Liang&#39;s Mines(简单dfs,需要注意重点)

Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1166    Accepted Submission(s): 505 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous