2024牛客暑期多校训练营5 L 知

链接:登录—专业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;
}

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值