隐藏
「广州集训 Day2」数学课 - 贪心 | Bill Yang's Blog

路终会有尽头,但视野总能看到更远的地方。

0%

「广州集训 Day2」数学课 - 贪心

题目大意

$n$个数任意取出两个数相乘再加$1$后再放入原序列,求出最后剩下的最小值。


题目分析

举个例子发现 (显然) 大的先乘起来会比较小。


代码

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
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
inline const LL Get_Int() {
LL num=0,bj=1;
char x=getchar();
while(x<'0'||x>'9') {
if(x=='-')bj=-1;
x=getchar();
}
while(x>='0'&&x<='9') {
num=num*10+x-'0';
x=getchar();
}
return num*bj;
}
const LL mod=1000000007;
LL n,a[205],ans;
int main() {
n=Get_Int();
for(int i=1; i<=n; i++)a[i]=Get_Int();
sort(a+1,a+n+1,greater<LL>());
ans=a[1];
for(int i=2; i<=n; i++)ans=(ans*a[i]+1)%mod;
printf("%lld\n",ans);
return 0;
}
姥爷们赏瓶冰阔落吧~