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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值