win7中用MinGW編譯x264出現"No working C compiler found."錯誤

來源:互聯網
上載者:User

標籤:des   style   blog   class   c   code   

Description

Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak.

Input

The input contains exactly one test case. The first line of input contains three positive integers n (n ≤ 30), k (k ≤ 109) and m (m < 104). Then follow n lines each containing n nonnegative integers below 32,768, giving A’s elements in row-major order.

Output

Output the elements of S modulo m in the same way as A is given.

Sample Input

2 2 40 11 1

Sample Output

1 22 3
代碼:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct mat{    int t[65][65];    void set()    {        memset(t,0,sizeof(t));    }} a,b;mat multiple(mat a,mat b,int n,int p){    int i,j,k;    mat temp;    temp.set();    for(i=0; i<n; i++)        for(j=0; j<n; j++)        {            if(a.t[i][j]>0)                for(k=0; k<n; k++)                    temp.t[i][k]=(temp.t[i][k]+a.t[i][j]*b.t[j][k])%p;        }    return temp;}mat quick_mod(mat b,int n,int m,int p){    mat t;    t.set();    for(int i=0;i<n;i++) t.t[i][i]=1;    while(m)    {        if(m&1)        {            t=multiple(t,b,n,p);        }        m>>=1;        b=multiple(b,b,n,p);    }    return t;}void init(int n,int m,int p){    a.set();    b.set();    for(int i=0;i<n;i++)    for(int j=0;j<n;j++)    {        scanf("%d",&b.t[i][j]);        b.t[i][j+n]=b.t[i][j];        a.t[i][j]=b.t[i][j];    }    for(int i=n;i<2*n;i++)    for(int j=n;j<2*n;j++)    if(i==j) b.t[i][j]=1;    for(int i=n;i<2*n;i++)    for(int j=0;j<n;j++)    if(j+n==i) a.t[i][j]=1;    b=quick_mod(b,2*n,m-1,p);    mat temp;    temp.set();    for(int i=0; i<n; i++)        for(int j=0; j<n; j++)        {                for(int k=0; k<2*n; k++)                    temp.t[i][j]=(temp.t[i][j]+b.t[i][k]*a.t[k][j])%p;   //錯誤一點,無限WA        }   for(int i=0;i<n;i++)   {       for(int j=0;j<n;j++)       printf("%d ",temp.t[i][j]);       puts("");   }}int main(){    int n,m,p;    while(cin>>n>>m>>p)    {        init(n,m,p);    }    return 0;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.