I(UVALive 7816)

                           I

此处通往题目

Hassan is a happy key maker. Every customer arrives with a safe-box key,

and asks him to create somecopies of the key. Each key has several cuts of 

different depths. The picture below shows a safe-box keywith 3 cuts. 

To make a copy, Hassan needs to make the same number of cuts with exactly 

the samesequence of depths in a new blank key.In the first days of his job, 

Hassan wasted many blankkeys to make copies. Most of the copied keys, however, 

didnot match the customer keys and he could not sell them.

He collected those copied keys in a trash-box, and now he isthinking 

of recycling them.When a new customer arrives, Hassan looks into the 

trashbox,collects all keys with the same number of cuts as thecustomer’s key, 

and counts the keys that can match the customer’skey. A key can match the 

customer’s key if it alreadyhas exactly the same sequence of cut depths, or 

the depth ofsome of its cuts can be increased to reach the same sequence.

Since this job is too hard for him, he has asked your help.For simplicity, 

you can assume that in any two keys with thesame number of cuts, 

the position of the cuts along the keysare identical.


Input

There are multiple test cases in the input. The first line of each test case contains two space-separatedintegers m as the number of cuts in the customer’s key (1 ≤ m ≤ 10), and n as the number of keyswith the same number of cuts in the trash-box (1 ≤ n ≤ 100). 

The second line of the test case consistsof m space-separated integers, as the depths of cuts in the customer’s key. Each of the next n linesalso contains m integers, as the depths of cuts in a trash-box key. The depth of cuts in each of thesen+ 1 keys are 1-digit positive integers given in the left-to-right order. The input terminates with a linecontaining ‘0 0’ which should not be processed.


Output

For each test case, print a single line containing the number of keys in the trash-box that either matchthe customer’s key or can be cut to match it.


Sample Input

4 1

3 2 1 3

2 2 1 2

4 1

4 2 2 2

3 2 2 3

5 3

2 2 4 2 2

2 3 4 3 2

1 1 3 2 2

2 2 2 2 2

0 0


Sample Output

1

0

2


题意:

第一行输入m和n,m是孔数,n是钥匙的数量。

第二行为要做的钥匙对应的孔的深度。

接下来n行是每把钥匙的孔的深度。

PS:孔的深度只能加深。

输出能得到第二行钥匙数据的数量。


代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[105][15];
int b[15];
int main()
{
    int m,n;
    while(~scanf("%d%d",&m,&n))
    {
        if(n==0&&m==0)
            break;
        for(int i=0; i<m; i++)
            scanf("%d",&b[i]);
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                scanf("%d",&a[i][j]);
        int ans=0,flag;
        for(int i=0; i<n; i++)
        {
            flag=1;
            for(int j=0; j<m; j++)
            {
                if(a[i][j]>b[j])  
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值