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
#include
#include
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; ib[j])  
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


你可能感兴趣的:(I(UVALive 7816))