zoukankan      html  css  js  c++  java
  • Codeforces 682B New Skateboard(DP)

    题目大概说给一个数字组成的字符串问有几个子串其代表的数字(可以有前导0)能被4整除。

    • dp[i][m]表示字符串0...i中mod 4为m的后缀的个数
    • 通过在i-1添加str[i]字符转移,或者以str[i]为新后缀的开头转移
     1 #include<cstdio>
     2 #include<cstring>
     3 using namespace std;
     4 char str[333333];
     5 long long d[333333][4];
     6 int main(){
     7     scanf("%s",str);
     8     for(int i=0; str[i]; ++i){
     9         ++d[i][(str[i]-'0')%4];
    10         for(int j=0; j<4; ++j){
    11             d[i+1][(j*10+str[i+1]-'0')%4]+=d[i][j];
    12         }
    13     }
    14     long long ans=0;
    15     for(int i=0; str[i]; ++i){
    16         ans+=d[i][0];
    17     }
    18     printf("%lld",ans);
    19     return 0;
    20 }
  • 相关阅读:
    C语言扩展题
    C语言第五题
    C语言第四题
    C语言第三题
    c语言第二题
    11
    游戏开发的一些想法
    openxml的视频教程
    JavaScript调试之console.log
    IPPatternConverter
  • 原文地址:https://www.cnblogs.com/WABoss/p/5677278.html
Copyright © 2011-2022 走看看