A1170 | [COCI-2008_2009-contest5]#5 LUBENICA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Children in school are having fun instead of listening to the teacher. With their iPhone devices the children throw watermelons at each other on the Facebook social site.
The game started when Goran threw one watermelon at each of his friends during the first class that day. During subsequent classes, all children (including Goran) behaved like this:
• If they had been hit by an odd number of watermelons during the previous class, they threw exactly one watermelon at each of their friends;
• If they had been hit by an even number of watermelons (including zero), then they hit each of their friends with two watermelons.
The children are numbered 1 through N, Goran obviously being number
1. The friend relationships between the children are also known.
Write a program that will calculate the total number of watermelons thrown after H classes.
The game started when Goran threw one watermelon at each of his friends during the first class that day. During subsequent classes, all children (including Goran) behaved like this:
• If they had been hit by an odd number of watermelons during the previous class, they threw exactly one watermelon at each of their friends;
• If they had been hit by an even number of watermelons (including zero), then they hit each of their friends with two watermelons.
The children are numbered 1 through N, Goran obviously being number
1. The friend relationships between the children are also known.
Write a program that will calculate the total number of watermelons thrown after H classes.
输入格式
The first line contains two integers N and H (1 ≤ N ≤ 20, 1 ≤ H ≤ 1000000 000), the number of kids and classes.
Each of the following N lines contains a string of N characters '0' or '1'. The character (A, B) in this matrix is '1' if children A and B are friends.
No child will be their own friend. The input matrix will be symmetric.
Each of the following N lines contains a string of N characters '0' or '1'. The character (A, B) in this matrix is '1' if children A and B are friends.
No child will be their own friend. The input matrix will be symmetric.
输出格式
Output the number of watermelons after H classes.
输入输出样例
输入 #1
4 1 0110 1001 1001 0110
输出 #1
2
输入 #2
4 2 0110 1001 1001 0110
输出 #2
14
输入 #3
5 3 01000 10110 01000 01001 00010
输出 #3
26
In test cases worth 50% of points, H will be at most 1000.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted