2018 ACM-ICPC 中国大学生程序设计竞赛线上赛

  •  512K

Description:

 
     
 
           
1
// Q.cpp
2
#include <iostream>
3
using namespace std;
4
const long long M = 1000000007;
5
const long long MAXL = 1000000;
6
long long a[MAXL];
7
long long Q(int n, long long t)
8
{
9
    if(n < 0) return t;
10
    return (Q(n - 1, t) + Q(n - 1, (t * a[n]) % M)) % M;
11
}
12
int main()
13
{
14
    int n;
15
    while(cin >> n)
16
    {
17
        for(int i = 0; i < n; ++i)
18
        {
19
            cin >> a[i];
20
            a[i] %= M;
21
        }
22
        cout << Q(n - 1, 1) << endl;
23
    }
24
    return 0;
25
}

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<n<=1000000

0<=a[i]<=10000

There are 100 test cases at most. The size of input file is less than 48MB. 

Output:

Maybe you can just copy and submit. Maybe not. 

样例输入

1
233
1
666

样例输出

234
667

这题直接贴它给的代码会出现程序内存超限的错误,所以要读懂它给出的代码,代码求的是n项序列,从1加到任意i项组合累乘之后之和的和,比如有3项,则答案为1+a[1] + a[2] + a[3] + a[1]*a[2]+a[1]*a[3]+a[2]*a[3] + a[1]*a[2]*a[3]

#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long unll;
typedef  long long ll;
const int m = 1e9 + 7;
int main()
{
    int n;
    ll a;
    ll ans;
    while(scanf("%d", &n) != EOF){
        ans = 1;
        for(int i = 0; i < n; i ++){
            scanf("%lld", &a);
            ans = ans * (a + 1) % m;
            //cout << a[i] <<endl;
        }
        //cout << n << endl;
        printf("%lld\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dreamjay1997/article/details/80053117