在我的电脑上code::blocks运行过不了,但代码是可以AC的,很是郁闷。
问了大神,知道了函数的参数是放在栈区,结构体太大的话,栈就爆了,如是后来就听从大神的意见用引用改写了。
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1853
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int Len_Matrix;
int Mod;
double value[205];
struct Matrix{
double M[205][205];
};
void Init_Matrix(Matrix & tmp){
for(int i=0;i<Len_Matrix;i++){
for(int j=0;j<Len_Matrix;j++){
if(i==j) tmp.M[i][j] = 1;
else tmp.M[i][j] = 0;
}
}
}
void Debug_Matrix(Matrix & tmp){
for(int i=0;i<Len_Matrix;i++){
for(int j=0;j<Len_Matrix;j++){
printf("%lf ",tmp.M[i][j]);
}
puts("");
}
}
void multiply(Matrix & a1,Matrix & a2,Matrix & ans){
for(int i=0;i<Len_Matrix;i++){
for(int j=0;j<Len_Matrix;j++){
ans.M[i][j] = 0;
for(int k=0;k<Len_Matrix;k++){
ans.M[i][j] += a1.M[i][k]*a2.M[k][j];
}
}
}
}
void Pow(Matrix & tmp,int nl,Matrix &ans){
Init_Matrix(ans);
Matrix temp1,temp2;
while(nl){
if(nl&1){
temp1 = ans;
multiply(temp1,tmp,ans);
}
temp1 = tmp;
temp2 = tmp;
multiply(temp1,temp2,tmp);
nl /= 2;
}
}
void Solve(Matrix & tmp,int m){
Matrix ans;
Pow(tmp,m,ans);
double zans = 0;
for(int i=0;i<Len_Matrix;i++){
zans += ans.M[i][Len_Matrix-1] * value[i];
}
printf("%.0lf\n",zans);
}
void Input(){
int n,m;
while(scanf("%d %d",&n,&m),n+m){
Matrix tmp;
Len_Matrix = n;
Init_Matrix(tmp);
for(int i=0;i<n;i++){
scanf("%lf",value+i);
}
int k;
scanf("%d",&k);
int tempi,tempj;
double temprate;
for(int i=0;i<k;i++){
scanf("%d %d %lf",&tempi,&tempj,&temprate);
tmp.M[tempi][tempj] += temprate;
tmp.M[tempi][tempi] -= temprate;
}
Solve(tmp,m);
}
}
void File(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
}
int main(void){
//File();
Input();
return 0;
}