链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
The game consists of n levels, and you know in advance the probability of passing each level, given as a1,a2,⋯,an, where ai are non-negative integers.
You can perform any number of operations. Each operation allows you to choose an index i (1≤i<n,ai+1>0,ai<100) and decrement ai+1a_{i+1}ai+1 by one while incrementing ai by one.
After performing operations, you start the game, aiming to maximize the probability of passing all levels.
Output the maximum probability multiplied by 100^n modulo 998244353.
输入描述:
The first line contains a positive integer T, indicating the number of test cases.For each test case: The first line contains a positive integer n. The second line contains n non-negative integers ai.
输出描述:
For each test case, output one non-negative integer, representing the result of the maximum probability multiplied by 100^n mod 998244353.
示例1
输入
5 4 1 2 3 4 4 4 3 2 1 2 2 2 1 1 2 2 3
输出
36 24 4 1 6
备注:
1001≤T,n,ai≤100.
题目大意:给你n个数,你可以进行一个操作:挑选一个下标 i ,使a [ i ]+1,a [ i+1 ]-1。经过数次操作,使得n个数的乘积最大值。
思路:只要确保a[ i ] < a[ i+1 ] 即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod=998244353;
int a[105];
signed main()
{
IOS
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
}
int f=1,ans=1;
while(f){
f=0;
for(int i=1;i<n;i++){
if(a[i]<a[i+1]){
a[i]++;
a[i+1]--;
f=1;
}
}
}
for(int i=1;i<=n;i++){
ans=ans*a[i]%mod;
}
cout << ans << endl;
}
return 0;
}