1214. Fluctuation series (choice question)

Insert picture description here
Idea: Yan's dp method
Insert picture description here
Regarding the expression code of the previous item
Insert picture description here
:

# include<iostream>
# include<cstring>
# include<cstdio>
# include<algorithm>
using namespace std;

const int N = 1010,MOD = 100000007;
int f[N][N];

int get_mod(int a,int b)//求a除以b的正余数
{
    
    
    return (a % b + b) % b;
}

int main()
{
    
    
    int n,s,a,b;
    cin >> n >> s >> a >> b;
    f[0][0] = 1;
    for(int i = 1;i < n;i++)
    {
    
    
        for(int j = 0;j < n;j++)
        {
    
    
            f[i][j] = (f[i - 1][get_mod(j - i * a,n)] + f[i - 1][get_mod(j + i * b,n)]) % MOD;
        }
    }
    //序列的长度是n,若当前数是x,需要组合n - 1个数,才变成S,所以相当于求从前n - 1个项中选,余数是s % n的方案数
    cout << f[n - 1][get_mod(s,n)] << endl;
    
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_45812180/article/details/114408645