51nod1354 Selected Numbers

Source: Internet
Author: User

01 Backpack tle.

Problem solving report (by System Message)
A DP, similar to a backpack, that is in the product state. First of all, the number of the election is not the K-minus. Then find out the approximate K, discretization. Then Dp[i][j] indicates the state of the first I-digit product is J. DP[I+1][J*A[I+1]]]+=DP[I][J].
DP[I+1][J]+=DP[I][J];
Total complexity is O (n*d (k) *log (d (k)))
D (k) indicates the number of factors in K. One more log is because of discretization, corresponding to the subscript when the two points to find.

In fact, I think that is to remove the useless state only with his approximate to update. Online some of the solving the map is also to avoid the useless state.

#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #include <cmath > #include <map>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i >=t;i--) #define CLR (x,c) memset (x,c,sizeof (x)) int read () {int X=0;char c=getchar (); while (!isdigit (c)) C=getchar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int Nmax=1e4+5;const int Mod=1e9+7;int a[nmax],ans[nmax];void mm (int &a) {if (a>=mod) a-=mod;} int main () {int t=read (), while (t--) {int n=read (), K=read (), cnt=0,u,v,d;for (v=1;v*v<k;v++) if (k%v==0) a[++cnt]=v,a[ ++cnt]=k/v;if (v*v==k) a[++cnt]=v;sort (a+1,a+cnt+1); Rep (i,1,cnt) Ans[i]=0;ans[1]=1;rep (i,1,n) {u=read (); if (k%u) Continue;dwn (j,cnt,1) {v=lower_bound (a+1,a+cnt+1,a[j]*u)-a;if (a[v]==a[j]*u) mm (Ans[v]+=ans[j]);}} printf ("%d\n", ans[cnt]);} return 0;}

  

1354 Select a digital base time limit: 1 seconds space limit: 131072 KB score: 80 Difficulty: 5-level algorithm topic collection attention when given a sequence a[0],a[1],a[2],..., a[n-1] and an integer k, we want to find out, How many sub-sequences satisfy such a condition: multiply all elements in the current sub-sequence to exactly equal K. Sample explanation:

For the first data, we can choose [3] or [1 (first 1), 3] or [1 (second 1), 3] or [1,1,3]. So the answer is 4.

Input
Multiple sets of test data. The first line of the input file has an integer t (0< t <= 20), which indicates that there is a T group of data. The next 2*t line will give each set of data a two-line data, the first line contains two integers n, K (1<=n<=1000,2<=k<=100000000) Their meaning has been mentioned above. The second line contains a[0],a[1],a[2],..., a[n-1] (1<= a[i]<=k) separated by a single space. All inputs are integers.
Output
For each data, the answer to 1000000007 after the output can be.
Input example
23 31 1 33 62 3 6
Output example
42

51nod1354 Selected Numbers

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.