abc310e <公式递推(dp?)>

题目

E - NAND repeatedly

思路

image

总结

  • 公式递推, 找到相邻两项间的关系;

代码

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1e6 + 10;
LL a[N];
LL b[N];
int n;
string s;

// LL cal(LL x, int n, bool y)
// {
//     if (y) return n - x;
//     else return n;
// }

void solv()
{
    cin >> n >> s; 
    int n = s.size();
    s = " " + s; 

    for (int i = 1; i <= n; i ++)
    {
        // b[i] = cal(b[i-1], i-1, s[i] - '0') + (s[i] - '0');
        int Ai = s[i] - '0';
        b[i] = (Ai ? (i-1 - b[i-1]) : i-1) + Ai;
        a[i] = a[i-1] + b[i];
    }
    cout << a[n] << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
	// cin >> T;
    while (T --)
    {
        solv();
    }
    return 0;
}

posted @   O2iginal  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示