1005-行列式

来源:互联网 发布:js中new array 编辑:程序博客网 时间:2024/04/30 09:30

题目大意:

给定a[1],a[2]...a[n],以及x。
求:行列式
|a[1]  -1  0  ...  0  0 |
|a[2]  x  -1  ...  0  0 |
|a[3]  0  x  ...  0  0 |
| .  .  .    .  . |
| .  .  .    .  . |
| .  .  .    .  . |
|a[n-1]  0  0  ...  x  -1|
|a[n]  0  0  ...  0  x |
的值。
由于结果很大,所以只要输出对结果除以1000000007的余数;


Input:

第一行是一个整数T,代表测试数据的组数。
对于每组测试数据,第一行是n(n<=10^5)和x(1<=x<=10^9),含义如题目描述。
接下来一行是n个整数a[1],a[2],a[3]...a[n]。(1<=a[i]<=10^9)


Output:

输出行列式的值除以1000000007的余数,输出结果占一行


Sample Input

23 21 2 34 11 2 3 4

Sample Output

1110
#include <iostream>#include <cstdio>#include <cstring>using namespace std;long long a[100010];int main(){int T;int i,j,n;long long sum,x;scanf("%d",&T);while(T--){scanf("%d%I64d",&n,&x);for(i=1;i<=n;i++){scanf("%I64d",&a[i]);}sum=a[1];for(i=2;i<=n;i++){sum=(a[i]+x*sum)%1000000007;}cout<<sum<<endl;}return 0;}

0 0
原创粉丝点击