Rokua's topic, and that's why. The tragic format = =
Valley 1164 small a à la carte
Address: http://www.luogu.org/problem/show?pid=1164
Topic backgroundUim god Ben got the Uoi ra (laser), immediately pull the base friend small A to a home ... Restaurant, very low-end kind. Uim points to the price list on the wall (too low-level without a menu) and says, "casually." Title Descriptionbut Uim bought some auxiliary (e) auxiliary (RO) books, only M yuan (m<=10000) left in his pocket.
Although the restaurant is low-end, but there are many varieties of dishes, there are N species (n<=100), the first I kind of sell Ai yuan (ai<=1000). Because it is a very low-end restaurant, there is only one dish for each vegetable.
small a adhere to the "Don't put the money to eat not to rest", so he order must be just right uim the money spent. He wanted to know how many ways to order.
because small a belly is too hungry, so can only wait 1 seconds. Input/output formatInput Format:
The first line is two digits, representing N and M.
The second line is n positive AI (can have the same number, each number is within 1000).
output Format:
A positive integer that represents the number of à la carte programs.
Input/Output sampleInput Sample # #:
4 41 1) 2 2
Sample # # of output:
3
It doesn't matter. = = Stick directly on it
The topic is very simple, almost backpack entry problem, in fact, strictly speaking is not a backpack, but the choice of principle is the same
The interpretation of the reference, the two-dimensional equation f[i,j]:=f[i-1,j]+f[i-1,j-a[i]];
The array is represented in the first I course, the total price is J.
You can not order the dish (f[i-1,j]), or Point (F[i-1,j-a[i])
Compressed space to one dimension, is
F[0]:=1; For I:=1 to N does for j:=m downto a[i] do f[j]:=f[j]+f[j-a[i]];
So directly on the code
--The dangerous wind is thin, looking very spring sorrow, dim the sky
Copyright NOTICE: Reprint Please specify source [ametake Copyright]http://blog.csdn.net/ametake Welcome to see
"Basic exercise" "Backpack DP" valley 1164 small a à la carte