0%

2022杭电杯超级联赛09

1010-Sum Plus Product

来源: 杭电杯超级联赛9 算法: 数论, 语法 题目链接: https://acm.dingbacode.com/contest/problem?cid=1052&pid=1010 补完: Yes 完成时间: August 16, 2022

题解

以球\(a,b,c\)为例推演发现, 不论谁先组合都有答案\(a+b+c+ab+ac+bc+abc\).

总体计算答案时可视为若干球依次放入\(ans +=new+new\cdot ans\)

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const ll P = 998244353;
const int MAXN = 505;

ll a[MAXN];

ll add(ll a, ll b){
return (a+b)%P;
}

ll mul(ll a, ll b){
return (a*b)%P;
}
void solve() {
int n;
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>a[i];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans = add(ans,add(a[i],mul(ans,a[i])));
}
cout<<ans<<"\n";
}

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