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

#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. js设计模式-门面模式

    适用场景:门面模式在DOM脚本编程这种需要对各种不一致的浏览器接口的环境中很常用. 例子:阻止模式事件 var DED = widow.DED || {}; DED.util = { stopProp ...

  2. ES6和Node容易搞混淆的点

    ES6 import  模块名 from XX  '模块标识符'     -----导入模块 import '路径 ' -----导入CSS样式 export default { }  和export ...

  3. Visual Studio写Cuda代码

    1. 正常新建一个项目   2. 在项目中右键, build 选项中选择 CUDA 编译器   3. 项目属性中设置 CUDA 链接库 和 头文件 编译参数等   4. 完成     cu cuh 文 ...

  4. CSS简单入门

    - Java攻城狮学习路线 - 一. 什么是CSS CSS指层叠样式表(Cascading Style Sheets),定义如何显示HTML元素 二. CSS语法 /* 选择器 { 声明: 声明:}* ...

  5. hdu2686/hdu3376 最小费用流最大流 拆点

    虽然题目求的是最大费用,但是我们可以通过转换就变为最小费用.用一个比最大值更的数与每个数的差作为费用值.最后处理回来就i可以了.有些人用直接每个值都乘以-1,这样更简单. 做这题,我对为什么不拆点就会 ...

  6. Sql Server 连接池

    在看缓存的一篇文章中,看到连接池的三个字,来充充电. 原文连接 这篇讲了关键字 其实我们一直在使用SqlServer的连接池.在连接字符串中,Pooling为是否启用连接池,默认值为true,表示启用 ...

  7. 将自己的类封装为lib的方法

    前言: Windows API中所有的函数都包含在dll中,其中有3个最重要的DLL. (1)   Kernel32.dll 它包含那些用于管理内存.进程和线程的函数,例如CreateThread函数 ...

  8. git基础讲解

    idea :https://blog.csdn.net/autfish/article/details/52513465 eclipse:https://blog.csdn.net/yang57266 ...

  9. spring cloud(四) feign

    spring cloud 使用feign进行服务间调用 1. 新建boot工程 pom引入依赖 <dependency> <groupId>org.springframewor ...

  10. Everything Be True FreeCodeCamp

    function every(collection, pre) { // Is everyone being true? for(var i in collection){ if(!collectio ...