Digital solution to a problem 51mod P1354 election

Daily questions day8 punch

Analysis

Discrete backpack +

This is the question we simulate a race T2, the result of my whole TLE of violence.

If, after the key is the product of two factors in discrete array factor is equal to the product itself, indicating a [j] * in the table after the discretized by + = ans [j] calculated

Then you can happily dp friends ~ ~ ~

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define maxn 1000+10
 6 #define mod 1000000007
 7 using namespace std;
 8 inline int read() 
 9 {
10     int x=0;
11     bool f=1;
12     char c=getchar();
13     for(; !isdigit(c); c=getchar()) if(c=='-') f=0;
14     for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0';
15     if(f) return x;
16     return 0-x;
17 }
18 inline void write(int x)
19 {
20     if(x<0){putchar('-');x=-x;}
21     if(x>9)write(x/10);
22     putchar(x%10+'0');
23 }
24 int T;
25 int n,k,cnt;
26 int a[maxn],bf[maxn],ans[maxn];
27 int main()
28 {
29     T=read();
30     while(T--)
31     {
32         memset(ans,0,sizeof(ans));
33         memset(a,0,sizeof(a));
34         cnt=0;
35         n=read();k=read();
36         for(int i=1;i*i<=k;i++)
37             if(k%i==0)
38             {
39                 if(i*i==k) 
40                 {
41                     a[++cnt]=i;
42                     continue; 
43                 }
44                 a[++cnt]=i;
45                 a[++cnt]=k/i;
46             }
47         sort(a+1,a+cnt+1);
48         ans[1]=1;
49         for(int i=1;i<=n;i++)
50         {
51             int in=read();
52             if(k%in!=0) continue;
53             for(int j=cnt;j>=1;j--)
54             {
55                 int ls=lower_bound(a+1,a+cnt+1,a[j]*in) - a;
56                  if (a [ls] == a [j] * in ) 
 57                  {
 58                      years [ls] + years [j];
59                      years [ls]% = mod;
60                  }
 61              }
 62          }
 63          printf ( " % d \ n " , years [cnt]);
64      }
 65      return  0 ;
66 }

Please Gangster treatise(Anyway, I do not know what that means treatise)

Guess you like

Origin www.cnblogs.com/handsome-zyc/p/11493798.html