Copy and Submit II

Posted zl-nirvana

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Copy and Submit II相关的知识,希望对你有一定的参考价值。

 

技术分享图片

 技术分享图片

 这题内存只有512k,直接提交的话肯定错,所以需要给他优化一下,首先就要看懂代码是在干什么

比如说如果是输入3个数 a,b,c,就应该输出1+a+b+c+ab+ac+bc+abc,当时做的时候就推到这一步,然后就不知道怎么做了,回来问了一下才知道有公式

1+a+b+c+ab+ac+bc+abc=(1+a)(1+b)(1+c)

这个样子就很好办了,我的代码如下:

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int M = 1000000007;
 6 
 7 int main()
 8 {
 9     int n,temp;
10     long long ans;
11     while (scanf("%d", &n)!=EOF)
12     {
13         ans = 1;
14         for (int i = 0; i < n; i++)
15         {
16             scanf("%d", &temp);
17             ans = (ans*(1 + temp) % M) % M;
18         }
19         printf("%ld\\n", ans);
20     }
21     return 0;
22 }

 

以上是关于Copy and Submit II的主要内容,如果未能解决你的问题,请参考以下文章