cf div2 D. Chip Move

cf div2 D. Chip Move_第1张图片

 题意:

从原点开始走,每一步走正整数步,第一步走k的倍数步,第二步走k+1的倍数步,问你走到[1,n]的方案数分别为多少。

分析:

cf div2 D. Chip Move_第2张图片

#include
// cout< 
#define M(a,b) make_pair(a,b)
#define fi first
#define se second
#define pb push_back
#define __builtin_popcount popcnt1//getcnt 
#define db1(x) cerr<<#x<<"="<<(x)<<" "
#define db2(x) cerr<<#x<<"="<<(x)<<"\n"
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _gcd(ll a, ll b) { return b > 0 ? _gcd(b, a % b) : a; }
int popcnt1(ll x) { int ans = 0;for (int j = 0;j <= 60;j++)if (x & (1ll << j)) ans++;return ans; }
template  inline void read(T& t) { int f = 0, c = getchar(); t = 0;while (!isdigit(c)) f |= c == '-', c = getchar();while (isdigit(c)) t = t * 10 + c - 48, c = getchar();if (f) t = -t; }
template  void print(T x) { if (x < 0) x = -x, putchar('-');if (x > 9) print(x / 10);putchar(x % 10 + 48); }
const double pi = acos(-1.0);
const double eps = 1e-7;//有时候精度可能不够
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int N = 3e5+10;
int n, m, t, k;
int a[N];
int f[N], dp[N],ans[N];
#define add(x,y) ((x+=y)>=mod?x-=mod:x);
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> k;
    int sum = 0;
    f[0] = 1;
    for (int i = 1;;i++) {
        int x = k + i - 1;
        sum += x;
        if (sum > n) break;
        for (int i = x;i <= n;i++) add(f[i], f[i - x]);
        for (int i = sum;i <= n;i++) add(ans[i], f[i - sum]);
    }
    for (int i = 1;i <= n;i++) {
        cout << ans[i] << " ";
    }cout << endl;
    return 0;
}

 

你可能感兴趣的:(算法)