【AtCoder Beginner Contest 253】E - Distance Sequence

简介: 笔记

题意


5.png


思路


6.png7.png

代码


  • 前缀和 + 动态规划
int n, m, k;
int f[M], s[M];
void solve() {
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) f[i] = 1; // i == 1;
  for (int i = 2; i <= n; i++) { // i > 1
    s[0] = 0;
    for (int j = 1; j <= m; j++)
      s[j] = (s[j - 1] + f[j]) % mod;
    int sum = s[m];
    for (int j = 1; j <= m; j++) {
      int l = max(1ll, j - k + 1);
      int r = min(m, j + k - 1);
      if(k > 0) f[j] = (sum - s[r] + s[l - 1] + mod) % mod;
      else f[j] = sum % mod;
    }
  }
  int res = 0;
  for (int i = 1; i <= m; i++) res = (res + f[i]) % mod;
  cout << res << endl;
}
相关文章
UVa11565 - Simple Equations
UVa11565 - Simple Equations
52 0
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
70 0
|
机器学习/深度学习
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
93 0
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
115 0
The 15th Chinese Northeast Collegiate Programming Contest C. Vertex Deletion(树形dp)
The 15th Chinese Northeast Collegiate Programming Contest C. Vertex Deletion(树形dp)
111 0
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
96 0
|
机器学习/深度学习
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
120 0
|
机器学习/深度学习
AtCoder Beginner Contest 218 C - Shapes (模拟)
AtCoder Beginner Contest 218 C - Shapes (模拟)
144 0
|
人工智能
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
114 0