码迷,mamicode.com
首页 > 其他好文 > 详细

行列式求值

时间:2015-03-01 11:44:05      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

var a:array[0..208,0..208] of int64;
    mo:int64;
    i,j,n,temp:longint;
function guess:int64;
var i,j,k,t:longint;
    ans:int64;
begin
    ans:=1;
    for i:=1 to n do
    begin
        for j:=i+1 to n do
        begin
            while a[j,i]<>0 do
            begin
                t:=a[i,i] div a[j,i];
                for k:=i to n do begin a[i,k]:=a[i,k]-t*a[j,k]; a[i,k]:=a[i,k] mod mo; end;
                for k:=1 to n do begin temp:=a[i,k]; a[i,k]:=a[j,k]; a[j,k]:=temp; end;
                ans:=-ans;
            end;
        end;
        if a[i,i]=0 then exit(0);
        ans:=ans*a[i,i] mod mo;
    end;
    if ans<0 then ans:=ans+mo;
    exit(ans);
 
end;
begin
    readln(n,mo);
    for i:=1 to n do
        for j:=1 to n do
            read(a[i,j]);
    writeln(guess);
end.
      

 

行列式求值

标签:

原文地址:http://www.cnblogs.com/rpSebastian/p/4306720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!