编程介的小学生 2017-02-13 03:03 采纳率: 20.5%
浏览 691
已采纳

Giftbox

Description

Bobobo and Bottle are good friends, and the birthday of Bottle is coming. So Bobobo is considering preparing Bottle an unexpected gift for his birthday. As a common sense that when a person at his or her birthday party, he or she will open the gift with the presence of the person who gives the gift and then expresses the appreciation. Bobobo knows that the characteristic of Bottle is rush when he receives something important, so he wants to play a joke on him in this way…

Bobobo comes into a gift shop, and there are a lot of different kinds of gift boxes. Bobobo intends to choose various boxes with different size and choose one of the gift boxes to contain the precious gift and place this box into another bigger box and place this bigger box into another bigger one… So Bottle will not see the gift until he opens the innermost box. Imagine the process of his opening the boxes, how rush Bottle will be ^_^ !

The gift boxes are n-dimensional. An n-dimensional box with dimensions ( X1, X2, …, Xn ) can be put into another box with dimensions ( Y1, Y2, …, Yn ) if there exists a permutation π on { 1, 2, …, n } such that Xπ1 < Y1, Xπ2 < Y2, …, Xπn < Yn. The gift is also n-dimensional and it can be put into a box if it satisfies the criterion above. And Bobobo must try his best to choose as many as boxes to contain the gift.

Input

The input file contains multiple test cases. The first line of each test case contains two numbers. The first one is a positive integer number N (1 ≤ N ≤ 500), the number of boxes in the gift shop, and the second one is a positive number d (3 ≤ d ≤ 1 000), the dimension of all the boxes. The next one line contains d positive integers ( G1, G2, …, Gd ) representing the dimensions of the gift. And the subsequent N lines each contain d positive integers ( X1, X2, …, Xd ) representing the dimensions of each box. You may assume that all the numbers you encounter are positive integers and less than 231. The input data is terminated by EOF.

Output

The output of each test case will contain only one line. Output the maximum number of the boxes that Bobobo can choose. If Bobobo can not find any box which can contain the gift, output “Please look for another gift shop!”

Sample Input

5 7
4 6 8 2 7 5 3
2 8 13 6 10 9 4
80 70 12 3 6 8 2
8 7 4 6 9 10 12
100 200 300 400 500 600 700
800 800 800 800 800 800 800
Sample Output

3

  • 写回答

2条回答 默认 最新

  • devmiao 2017-02-13 18:24
    关注

    #include
    #include
    int ans[501][1001],a[501],dp[501];
    struct P{
    int w[1001];
    }s[501];
    bool cmp(P a,P b)
    {
    return a.w[0]<b.w[0];
    }
    int main()
    {
    int i,j,l,k,n,m,r;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
    for(i=0;i<m;i++)scanf("%d",&a[i]);
    std::sort(a,a+m);

        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)scanf("%d",&s[i].w[j]);
            std::sort(s[i].w,s[i].w+m);
        }
        std::sort(s,s+n,cmp);
    
        for(l=0,i=0;i<n;i++)
        {
            for(k=0;k<m;k++)
                if(s[i].w[k]<=a[k])break;
            if(k==m)
            {
                for(k=0;k<m;k++)ans[l][k]=s[i].w[k];
                l++;
            }
        }
        if(l==0)
            printf("Please look for another gift shop!\n");
        else
        {
            for(i=0;i<l;i++)dp[i]=1;
            for(r=dp[0],i=1;i<l;i++)
            {
                for(j=0;j<i;j++)
                {
                    for(k=0;k<m;k++)
                        if(ans[i][k]<=ans[j][k])break;
                    if(k==m)
                        dp[i]=dp[i]>dp[j]+1?dp[i]:dp[j]+1;
                }
                if(dp[i]>r)r=dp[i];
            }
            printf("%d\n",r);
        }
    }return 0;
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题