題意:
矩陣的第一行是
23 233 2333 23333…..
給出n*m矩陣的第一列,其他都滿足f[i,j]=f[i-1,j]+f[i,j-1]
求f[n,m]
思路:
我們對於每行進行推導,發現一些規律
f[0]=f[0]*10+3
f[1]=f[1]+f[0]*10+3
f[2]=f[2]+f[1]+f[0]*10+3
…. 這樣,我們就能搞出來乙個n+2*n+2的矩陣,比如n==3的時候
10 10 10 10 0
0 1 1 1 0
0 0 1 1 0
0 0 0 1 0
1 1 1 1 1
原矩陣就是
a[0] a[1] a[2] a[3] 3
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
另外…這道題能用數學方法過…0ms(orz
給出鏈結
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using
namespace
std;
#define lowbit(x) (x&(-x))
typedef
long
long ll;
const
int maxn = 100005;
const
int inf=(1
<<28)-1;
#define matrix_size 12
const ll mod = 1e7+7;
int size;
struct matrix
void output()
}matrix operator *(const matrix &b)const
}return ret;
}};matrix pow_m(matrix a,long
long n)
return ret;
}int main()
b.mat[n+1][n+1]=1;
if(m==0)
b=pow_m(b,m);
a=a*b;
printf("%d\n",a.mat[0][n]);
}return
0;}
POJ 3233,HDU 5015 矩陣快速冪
poj 3233 利用矩陣快速冪推出轉移矩陣。注意什麼時候取模,同時用printf一定要注意格式的問題,與型別要匹配。這次的轉移矩陣是由一些子矩陣構成,不再是一些普通的常數了。left e e o a end right times left s a k end right left s k a e...
hdu5015 矩陣快速冪233(好題)
題意 給你乙個 n 1 m 1 的矩陣mat,然後給你mat 0 1 233 mat 0 2 2333,mat 0 3 23333.然後輸入mat 1 0 mat 2 0 mat 3 0 然後給了矩陣中的其他數值是mat i j mat i 1 j mat i j 1 最後讓你輸出mat n m 思...
hdu 1005 構造矩陣基礎題
題意 a number sequence is defined as follows f 1 1,f 2 1,f n a f n 1 b f n 2 mod 7.given a,b,and n,you are to calculate the value of f n 思路 這道題如果初看,本想對7...