跳到正文

题解

题解:P1001 A+B Problem

chenyuan3约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月10日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P1001

版本

  1. v1当前

一道 ST 表板子题,但是弱化了很多。

C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n = 2, a[200], st[200][200];
void solve()
{
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
        st[i][0] = a[i];
    }
    for (ll j = 1; j <= n; j++)
    {
        for (ll i = 1; i <= n; i++)
        {
            if (i + (1 << j) - 1 > n)
            {
                break;
            }
            st[i][j] = st[i][j - 1] + st[i + (1 << j - 1)][j - 1];
        }
    }
    cout << st[1][1];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
 	// ll t; cin >> t; while (t--)
	solve();
	return 0;
}
原文