Seventh session of Henan province A. Material dispatch (DFS)

Source: Internet
Author: User

10401:a. Material dispatch time Limit:2 Sec Memory limit:128 MB submit:95 solved:54 [Submit][status][web Board] Description

earthquake in a certain area, the disaster area has been very difficult, the victims urgently need some tents, clothing, food and plasma and other supplies. The road to the disaster area is full of landslides,70% above the road damage, the bridge is all destroyed. The state immediately launched emergency preparedness plans, the history of the largest non-combat air transport operations, ready to drop urgently needed supplies to the disaster area.

one side has difficulty , p plus support. There are now known to have N places, respectively , A1,A2,...., an material for deployment. At present, the disaster area needs the quantity of M.

Now, ask your help to calculate the total number of material scheduling schemes.

Suppose a place is chosen to be leveled, the number of its material is taken away.

Input

First line: K indicates how many sets of test data are available.

Next, there are 2 rows for each set of test data, line 1 : N M

Line 2nd: A1 A2 ... an

2≤K≤8     1<n≤ 1<m ≤ +     1≤ Ai≤1 the 

All data is a positive integer. There is a space between the input data.

Assume that a given data has at least one scheduling scheme.

Output

for each set of test data, output one line: Total programme number of material dispatch

Sample Input
24 41 1 2 24 61 1 2 2
Sample Output
31
HINT Source

Seventh session of Henan Provincial race

The puzzle: Dfs ... DP had not come out for half a day;;

Code:

#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include < Algorithm> #include <set>using namespace std; #define MEM (x, y) memset (x,y,sizeof (×)) #define SI (x) scanf ("%d", &X) #define SL (x) scanf ("%lld", &x) #define  PI (x) printf ("%d", x) #define  PL (x) printf ("%lld", x) #define  P_ printf ("") const int Inf=0x3f3f3f3f;const double Pi=acos ( -1.0); typedef long Long ll;const int Maxn=1010;int m[maxn];int N,m,ans;int vis[maxn];void dfs (int sum,int pos) {if (sum==m) {Ans++;return;} if (sum>m) return;for (int i=pos;i<n;i++) {if (Sum+m[i]<=m&&!vis[i]) {Vis[i]=1;dfs (sum+m[i],i+1); Vis [I]=0;}}} int main () {int t;si (T), while (t--) {si (N), Si (M), mem (vis,0), for (int i=0;i<n;i++) SI (M[i]), sort (m,m+n), Ans=0;dfs ( 0,0);p rintf ("%d\n", ans);} return 0;}

  

Seventh session of Henan province A. Material dispatch (DFS)

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.