Rokua P2409 Y's building blocks

Source: Internet
Author: User

Topic background

Y is a big architect who can always use the simplest bricks to create the most creative styling.

Title Description

Y has n boxes of bricks on hand, each with a weight. Now he wants to take a block of bricks from each box and put them together, the weight of each block is the weight of the bricks. Now he wants to know how much weight and the smallest K-type are the weights respectively. (Whenever a block is replaced, it is considered a different method.) If the sum of the various weights is the same, we need to output multiple times. )

Input/output format Input Format:

The first line enters two integers, n,k, meaning as described in the topic.

The next n rows for each set of data, the first integer is MI, which represents the number of block I blocks, and in the same row there are mi integers, each representing the weight of each building block.

output Format:

One line, the weight of the smallest K-type extraction, requires for each data, from small to large output

Input/Output sample Input Sample # #:
3 104 1 3 4 53 1 7 94 1 2 3 5
Sample # # of output:
3 4 5 5 6 6 7 7 7 7
Description

For 30% data: 2<=mi<=10,1<=n<=10

For 50% data: 2<=mi<=50,1<=n<=50

For 100% of data: 2<=mi<=100,1<=n<=100,1<=k<=10000, the weight of each block is not more than 100 positive integer, all MI product is greater than or equal to K. I don't usually have a card.

Sum not more than 10000, packet backpack DP, see the value X can be combined several times, and then from small to large output k can be combined number of times

1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 #defineLL Long Long8 using namespacestd;9 Const intmxn=101;Ten intRead () { One     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; the } - intn,k; - intM[MXN]; - intA[MXN][MXN]; + intf[mxn][mxn*MXN]; - intSMM[MXN]; + intMain () { AN=read (); k=read (); at     inti,j; -     intmx=0; -      for(i=1; i<=n;++i) { -mx=0; -m[i]=read (); -          for(j=1; j<=m[i];++j) { ina[i][j]=read (); -             if(A[I][J]&GT;MX) mx=A[i][j]; to         } +Sort (a[i]+1, a[i]+m[i]+1); -smm[i]=smm[i-1]+MX; the     } *f[0][0]=1; $      for(i=1; i<=n;++i) {Panax Notoginseng          for(j=smm[i];j;--j) { -              for(intL=1; l<=m[i];++l) { the                 if(A[I][L]&GT;J) Break; +f[i][j]+=f[i-1][j-A[i][l]]; A             } the         } +     } -      for(i=1; i<=smm[n];++i) { $          while(F[n][i] &&k) { $--f[n][i];--K; -printf"%d", i); -         } the     } -     return 0;Wuyi}

Rokua P2409 Y's building blocks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.