题目链接
简单题
Description:
Input:
Input consists of several test cases. Each test case begins with an integer n. Then it’s followed by n integers a[i].
0
Output:
Maybe you can just copy and submit. Maybe not.
这个地方有点Bug (lll¬ω¬)
样例输入:
1
233
1
666
样例输出
234
667
题意:
就是给你一段代码,你可以选择直接提交,也可以选择不直接提交。内存限制才512k。
思路:
(lll¬ω¬) 直接提交肯定内存爆炸的。先看懂这段代码是干啥的,然后再优化。
其实也不难推,很轻易就可以发现,这段代码的作用。假设这个是三个数,n = 3,这三个数分别为,a,b,c.则这段代码的作用是求1+a+b+c+ab+ac+bc+abc。可以提取公因式 = (1+a)(1+b)(1+c);
这样以来就非常简单了。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3+5;
typedef long long ll;
const int MOD = 1000000007;
int n;
int main(){
while(~scanf("%d",&n)){
ll ans = 1;
int temp;
for(int i=0;i<n;i++){
scanf("%d",&temp);
ans = (ans*(1+temp)%MOD)%MOD;
}
cout<<ans<<endl;
}
return 0;
}