Zoj 2853 Evolution Matrix Fast Power

Source: Internet
Author: User

On my computer code::blocks run too, but the code can be AC, it is depressed.

Asked the great God, know that the parameters of the function is placed in the stack area, the structure is too large, the stack will explode, and then listen to the views of the great God with reference rewrite.

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


Zoj 2853 Evolution Matrix Fast Power

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.