A:Stones
้ข็ฎ๏ผ
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains ๐ stones, the second of them contains ๐ stones and the third of them contains ๐ stones.
Each time she can do one of two operations:
take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesnโt know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer ๐ก (1โค๐กโค100) โ the number of test cases. Next ๐ก lines describe test cases in the following format:
Line contains three non-negative integers ๐, ๐ and ๐, separated by spaces (0โค๐,๐,๐โค100) โ the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so ๐ก=1 should be satisfied.
Output
Print ๐ก lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer โ the maximum possible number of stones that Alice can take after making some operations.
Example
input
1 | 3 |
output
1 | 9 |
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9.
้ข่งฃ๏ผ
bไธc่ฝ่ฟ่กๅคๅฐๆไฝๅฐฑๅๅคๅฐ๏ผ็ถๅๅฉไธ็bไธa็่ฝๅคๅๅคๅฐ๏ผ็ถๅๅใ
ไปฃ็ ๏ผ
1 | #include<stdio.h> |
B๏ผAlice and the List of Presents
้ข็ฎ๏ผ
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are ๐ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are ๐ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of ๐ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
She wonโt pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of ๐ kinds, empty boxes are allowed);
For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 109+7.
See examples and their notes for clarification.
Input
The first line contains two integers ๐ and ๐, separated by spaces (1โค๐,๐โค109) โ the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer โ the number of ways to pack the presents with Aliceโs rules, calculated by modulo 109+7
Examples
input
1 | 1 3 |
output
1 | 7 |
input
1 | 2 2 |
output
1 | 9 |
Note
In the first example, there are seven ways to pack presents:
{1}{}{}
{}{1}{}
{}{}{1}
{1}{1}{}
{}{1}{1}
{1}{}{1}
{1}{1}{1}
In the second example there are nine ways to pack presents:
{}{1,2}
{1}{2}
{1}{1,2}
{2}{1}
{2}{1,2}
{1,2}{}
{1,2}{1}
{1,2}{2}
{1,2}{1,2}
For example, the way {2}{2} is wrong, because presents of the first kind should be used in the least one box.
้ข่งฃ๏ผ
pow(pow(2,m)-1),n) + ๅฟซ้ๅน
ไปฃ็ ๏ผ
1 | #include<stdio.h> |
C:Labs
้ข็ฎ๏ผ
In order to do some research, ๐2 labs are built on different heights of a mountain. Letโs enumerate them with integers from 1 to ๐2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest place, โฆ, the lab with the number ๐2 is at the highest place.
To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number ๐ข to the lab with the number ๐ฃ if ๐ข>๐ฃ.
Now the labs need to be divided into ๐ groups, each group should contain exactly ๐ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group ๐ด to a group ๐ต is equal to the number of pairs of labs (๐ข,๐ฃ) such that the lab with the number ๐ข is from the group ๐ด, the lab with the number ๐ฃ is from the group ๐ต and ๐ข>๐ฃ. Letโs denote this value as ๐(๐ด,๐ต) (i.e. ๐(๐ด,๐ต) is the sum of units of water that can be sent from a group ๐ด to a group ๐ต).
For example, if ๐=3 and there are 3 groups ๐, ๐ and ๐: ๐={1,5,6},๐={2,4,9} and ๐={3,7,8}. In this case, the values of ๐ are equal to:
๐(๐,๐)=4 because of 5โ2, 5โ4, 6โ2, 6โ4,
๐(๐,๐)=2 because of 5โ3, 6โ3,
๐(๐,๐)=5 because of 2โ1, 4โ1, 9โ1, 9โ5, 9โ6,
๐(๐,๐)=4 because of 4โ3, 9โ3, 9โ7, 9โ8,
๐(๐,๐)=7 because of 3โ1, 7โ1, 7โ5, 7โ6, 8โ1, 8โ5, 8โ6,
๐(๐,๐)=5 because of 3โ2, 7โ2, 7โ4, 8โ2, 8โ4.
Please, divide labs into ๐ groups with size ๐, such that the value min๐(๐ด,๐ต) over all possible pairs of groups ๐ด and ๐ต (๐ดโ ๐ต) is maximal.
In other words, divide labs into ๐ groups with size ๐, such that minimum number of the sum of units of water that can be transported from a group ๐ด to a group ๐ต for every pair of different groups ๐ด and ๐ต (๐ดโ ๐ต) as big as possible.
Note, that the example above doesnโt demonstrate an optimal division, but it demonstrates how to calculate the values ๐ for some division.
If there are many optimal divisions, you can find any.
Input
The only line contains one number ๐ (2โค๐โค300).
Output
Output ๐ lines:
In the ๐-th line print ๐ numbers, the numbers of labs of the ๐-th group, in any order you want.
If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
Example
input
1 | 3 |
output
1 | 2 8 5 |
Note
In the first test we can divide 9 labs into groups {2,8,5},{9,3,4},{7,6,1}.
From the first group to the second group we can transport 4 units of water (8โ3,8โ4,5โ3,5โ4).
From the first group to the third group we can transport 5 units of water (2โ1,8โ7,8โ6,8โ1,5โ1).
From the second group to the first group we can transport 5 units of water (9โ2,9โ8,9โ5,3โ2,4โ2).
From the second group to the third group we can transport 5 units of water (9โ7,9โ6,9โ1,3โ1,4โ1).
From the third group to the first group we can transport 4 units of water (7โ2,7โ5,6โ2,6โ5).
From the third group to the second group we can transport 4 units of water (7โ3,7โ4,6โ3,6โ4).
The minimal number of the sum of units of water, that can be transported from one group to another is equal to 4. It can be proved, that it is impossible to make a better division.
้ข่งฃ๏ผ
ๆฏๆฌกๅๆฐ็ป็ไธค่พนไปฅๅไธญ้ดไฝ็ฝฎใ
ไปฃ็ ๏ผ
1 | #include<stdio.h> |