Untitled
unknown
plain_text
2 years ago
2.1 kB
11
Indexable
// Nhan ma tran
#include <iostream>
using namespace std;
int M = 1e8+7;
long long res[105][105];
long long a[105][105];
int n;
void MulArr(long long x[105][105], long long y[105][105]){
long long z[105][105];
for(long i=0; i<n; i++){
for(long j=0; j<n; j++){
z[i][j] = 0;
for(long k=0; k<n; k++){
z[i][j] += (x[i][k] % M) * (y[k][j] % M);
z[i][j] %= M;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
res[i][j] = z[i][j];
}
}
}
void Sub(long long x[105][105], long long y[105][105]){
for(long i=0; i<n; i++){
for(long j=0; j<n; j++){
x[i][j] = y[i][j];
}
}
}
void power(long long c[105][105], long m){
if(m==1)
return;
if(m%2==0){
power(c, m/2);
MulArr(res, res);
}
else{
power(c, (m-1)/2);
MulArr(res, res);
MulArr(res, a);
}
}
int main(){
//freopen("input.txt", "r", stdin);
int t;
cin >> t;
for(int tc=1; tc<=t; tc++){
long m;
cin >> n >> m;
for(long i=0; i<n; i++){
for(long j=0; j<n; j++){
cin >> a[i][j];
}
}
Sub(res, a);
power(a, m);
cout << "Case #" << tc << endl;
for(long i=0; i<n; i++){
for(long j=0; j<n; j++){
cout << res[i][j] << " ";
}
cout << endl;
}
}
return 0;
}
// Partition 1
#include <iostream>
using namespace std;
int main(){
//freopen("input.txt", "r", stdin);
int t;
cin >> t;
for(int tc=1; tc<=t; tc++){
int n;
cin >> n;
int a[1000];
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
if(a[i]>a[j]){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
int sum = 0;
int tmp = a[0]+a[1];
sum += tmp;
for(int i=1; i<n-1; i++){
a[i] = tmp;
for(int j=i; j<n-1; j++){
for(int z=j+1; z<n; z++){
if(a[j]>a[z]){
int temp1 = a[j];
a[j] = a[z];
a[z] = temp1;
}
}
}
tmp = a[i]+a[i+1];
sum += tmp;
}
cout << "Case #" << tc << endl;
cout << sum << endl;
}
return 0;
}Editor is loading...