3 条题解

  • 13
    @ 2022-12-11 17:54:50
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 100010, mod = 5000011;
    int f[N];
    int main()
    {
        int n, k, x = 0, tmp = 1;
        cin >> n >> k;
        f[0] = 1;
        for (int i = 1; i <= n; i += 1)
        {
            (f[i] += tmp) %= mod;
            if (i - k > 0)
            {
                (tmp += f[i - k]) %= mod;
            }
        }
        for (int i = 0; i <= n; i += 1)
        {
            (x += f[i]) %= mod;
        }
        cout << x << endl;
        return 0;
    }
    
    • 1
      @ 2024-4-6 16:40:02

      代码

      # include <bits/stdc++.h>
      
      using namespace std ;
      
      const int N = 100010 , mod = 5000011 ;
      
      int f [ N ] ;
      
      int main ( )
      
      {
      
          int n , k , x = 0 , tmp = 1 ;
      
          cin >> n >> k ;
      
          f [ 0 ] = 1 ;
      
          for ( int i = 1 ; i <= n ; i += 1 )
      
          {
      
              ( f [ i ] += tmp ) %= mod ;
      
              if ( i - k > 0 )
      
              {
      
                  ( tmp += f [ i - k ] ) %= mod ;
      
              }
      
          }
      
          for ( int i = 0 ; i <= n ; i += 1 )
      
          {
      
              ( x += f [ i ] ) %= mod ;
      
          }
      
          cout << x << endl ;
      
          return 0 ;
          
      }
      
      • 0
        @ 2022-7-14 20:00:15

        本题属于动态规划

      • 1

      信息

      ID
      1908
      时间
      1000ms
      内存
      256MiB
      难度
      2
      标签
      递交数
      127
      已通过
      80
      上传者