A9062 | Greg and Friends
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
One day Greg and his friends were walking in the forest. Overall there were $n$ people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold people with the total weight of at most $k$ kilograms.
Greg immediately took a piece of paper and listed there the weights of all people in his group (including himself). It turned out that each person weights either 50 or 100 kilograms. Now Greg wants to know what minimum number of times the boat needs to cross the river to transport the whole group to the other bank. The boat needs at least one person to navigate it from one bank to the other. As the boat crosses the river, it can have any non-zero number of passengers as long as their total weight doesn't exceed $k$ .
Also Greg is wondering, how many ways there are to transport everybody to the other side in the minimum number of boat rides. Two ways are considered distinct if during some ride they have distinct sets of people on the boat.
Help Greg with this problem.
Greg immediately took a piece of paper and listed there the weights of all people in his group (including himself). It turned out that each person weights either 50 or 100 kilograms. Now Greg wants to know what minimum number of times the boat needs to cross the river to transport the whole group to the other bank. The boat needs at least one person to navigate it from one bank to the other. As the boat crosses the river, it can have any non-zero number of passengers as long as their total weight doesn't exceed $k$ .
Also Greg is wondering, how many ways there are to transport everybody to the other side in the minimum number of boat rides. Two ways are considered distinct if during some ride they have distinct sets of people on the boat.
Help Greg with this problem.
输入格式
The first line contains two integers $n$ , $k$ $(1<=n<=50,1<=k<=5000)$ — the number of people, including Greg, and the boat's weight limit. The next line contains $n$ integers — the people's weights. A person's weight is either $50$ kilos or $100$ kilos.
You can consider Greg and his friends indexed in some way.
You can consider Greg and his friends indexed in some way.
输出格式
In the first line print an integer — the minimum number of rides. If transporting everyone to the other bank is impossible, print an integer -1.
In the second line print the remainder after dividing the number of ways to transport the people in the minimum number of rides by number $1000000007$ $(10^{9}+7)$ . If transporting everyone to the other bank is impossible, print integer $0$ .
In the second line print the remainder after dividing the number of ways to transport the people in the minimum number of rides by number $1000000007$ $(10^{9}+7)$ . If transporting everyone to the other bank is impossible, print integer $0$ .
输入输出样例
输入 #1
1 50 50
输出 #1
1 1
输入 #2
3 100 50 50 100
输出 #2
5 2
输入 #3
2 50 50 50
输出 #3
-1 0
In the first test Greg walks alone and consequently, he needs only one ride across the river.
In the second test you should follow the plan:
1. transport two $50$ kg. people;
2. transport one $50$ kg. person back;
3. transport one $100$ kg. person;
4. transport one $50$ kg. person back;
5. transport two $50$ kg. people.
That totals to $5$ rides. Depending on which person to choose at step 2, we can get two distinct ways.
In the second test you should follow the plan:
1. transport two $50$ kg. people;
2. transport one $50$ kg. person back;
3. transport one $100$ kg. person;
4. transport one $50$ kg. person back;
5. transport two $50$ kg. people.
That totals to $5$ rides. Depending on which person to choose at step 2, we can get two distinct ways.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted