知道了怎么置换之后,就可以用矩阵来置换了,但这道题一直关于置换的地方读不明白。

#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; const int Maxn=100;
int pn[Maxn],xn[Maxn],bn[Maxn];
int ansp[Maxn];
char str[Maxn];
struct Matrax {
int m[Maxn][Maxn];
};
int n,m;
Matrax per,a; void initial(){
memset(per.m,0,sizeof(per.m));
for(int i=0;i<n;i++){
per.m[i][i]=1;
}
memset(a.m,0,sizeof(a.m));
for(int i=0;i<n;i++)
a.m[pn[i]][i]=1;
} Matrax multi(Matrax ae,Matrax b){
Matrax c;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c.m[i][j]=0;
for(int k=0;k<n;k++){
c.m[i][j]+=ae.m[i][k]*b.m[k][j];
}
}
}
return c;
} Matrax quick(int k){
Matrax ans=per;
Matrax p=a;
while(k){
if(k&1){
ans=multi(ans,p);
}
k=k>>1;
p=multi(p,p);
}
return ans;
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
if(n==0&&m==0) break;
for(int i=0;i<n;i++){
scanf("%d",&bn[i]);
bn[i]--;
xn[i]=i;
}
for(int i=0;i<n;i++) //为什么要加这个,我想不明白,只好跟着别人加了
pn[bn[i]]=i;
getchar();
gets(str);
initial();
Matrax ans=quick(m);
for(int i=0;i<n;i++){
ansp[i]=0;
for(int k=0;k<n;k++)
ansp[i]+=xn[k]*ans.m[k][i];
}
for(int i=0;i<n;i++)
cout<<str[ansp[i]];
cout<<endl;
}
return 0;
}

  

HDU 2371的更多相关文章

  1. 矩阵十题【五】 VOJ1049 HDU 2371 Decode the Strings

    题目链接:https://vijos.org/p/1049 题目大意:顺次给出m个置换,重复使用这m个置换对初始序列进行操作.问k次置换后的序列.m<=10, k<2^31. 首先将这m个 ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. swift+moya URLCahe

    1.定义获取缓存策略的接口 import Foundation protocol CachePolicyGettable { var cachePolicy: URLRequest.CachePoli ...

  2. iOS- &quot;unacceptable content-type: text/plain&quot;等content-type bug解决方式

    常常在使用AFN的时候会出现content-type错误,缺少请求类型,比方"unacceptable content-type: text/plain" 解决方法: 1.在网络请 ...

  3. Linux - vim的基本使用

    通过which指令来查看文件位置! [root@local ~]# which vim /usr/bin/vim [root@local ~]# which vi /usr/bin/vi [root@ ...

  4. [POJ 3621] Sightseeing Cows

    [题目链接] http://poj.org/problem?id=3621 [算法] 01分数规划(最优比率环) [代码] #include <algorithm> #include &l ...

  5. [ZJOI 2010] 数字计数

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1833 [算法] 数位DP [代码] #include <algorithm&g ...

  6. php mktime和strtotime

    本文章来给各位同学介绍一下利用php用strtotime或mktime指定日期数据(本周,上周,本月,上月,本季度)实例,希望对各位同学会有所帮助呀. strtotime定义和用法 strtotime ...

  7. c语言递归讲解分析

    C语言允许函数调用它自己,这种调用的过程称为"递归(recursion)" 举例说明,如下代码: #include <stdio.h> void up_and_down ...

  8. JDBC数据库中表更新

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  9. POJ 3620 DFS

    题意: 给你n*m的矩形,有k个坏点 问最大坏点连通块的坏点数. 一发水题.. 裸的DFS // by SiriusRen #include <cstdio> #include <a ...

  10. Codeforces Round #448

    Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...