Sequence is divisible by 3 (simple DP)

Links: https://ac.nowcoder.com/acm/problem/21302
Source: Cattle-off network

Title Description

To give you a numeric string of length 50, you ask how many sub sequence of digital may be divisible
answers modulo 1e9 + 7

Enter a description:

Enter a string composed of a number, equal to the length of less than 50

Output Description:

An integer output

Specific ideas:

DP [i] [j] denotes the i-th character before the remainder could Couchu j is the number of

AC Code:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 # define ll long long
 4 # define inf 0x3f3f3f3f
 5 const int maxn  = 2e5+100;
 6 const int mod =1e9+7;
 7 char str[maxn];
 8 ll dp[maxn][10];
 9 int main()
10 {
11     scanf("%s",str+1);
12     int len=strlen(str+1);
13     int tmp=0;
14     for(int i=1; i<=len; i++)
15     {
16       dp[i][(str[i]-'0')%3]=1;
17             for(int j=0; j<3; j++)
18             {
19                 dp[i][j]+=dp[i-1][j];
20                 dp[i][j]%=mod;
21                 DP [I] [J] + DP = [I- . 1 ] [(J + 15 - (STR [I] - ' 0 ' ))% . 3 ]; // It should be noted that the complementary
 22 is                  DP [I] [J ]% = MOD;
 23 is              }
 24  //             COUT I << << endl;
 25  //             for (int J = 0; J <. 3; J ++) {
 26 is  //             COUT J << << "" << DP [ I] [J] << endl;
 27  //             } 
28      }
 29  //         COUT I << << endl;
 30  //         for (int J = 0; J <. 3; J ++) {
 31 is  //        cout<<j<<" "<<dp[i][j]<<endl;
32 //        }
33     printf("%lld\n",dp[len][0]);
34     return 0;
35 }

 

Guess you like

Origin www.cnblogs.com/letlifestop/p/10958733.html