|
|
|
[原创]各位煎熬中的临时用户有褔了!!!
这个,有意思。。。。么?O(∩_∩)O~ |
|
[讨论]大家没有获得转正资格的着急吗?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 成为会员最好也最简单的方法: 诚心写个技术帖子。 kanxue是为了促进大家学习的,不是促进大家挂机的。 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>挂成正式会员有什么用呢?>>>>>>> |
|
|
|
|
|
动态规划用于加密初探(1)(2)
2.使用LIS的算法太简单,O(n^2)的DP,哪怕是反汇编也一眼就看完了,建议可以改进成O(nlogn)的LIS算法(有DP和贪心两种)。并且可以考虑把LIS计算过程中的方案也求出来,并用到加密上,就会强大许多。 ----------------------这个学习了。---------------- 您们搞破解,我来学加密。 /* Name: 动态规划用于软件加密初探(2) Copyright: @Green Tsai Author: Green Tsai Date: 04-03-10 13:09 Description: 1,思路与思想:本程序试图将动态规划算法用于软件加密,主要涉及动态规划中的字符串编辑距离与相似度判定。 2,本程序中的编辑代价函数与相似度判定函数均可调整来增加加密强度与逆向难度。 3,示例姓名:kanxue,序列号:90yxop。 参考文档:《挑战编程》 Steven S.Skiena著 刘汝佳 译 */ #include <cstdlib> #include <iostream> using namespace std; #define MAXLEN 35 #define MATCH 0 // enumerated type symbol for match #define INSERT 1 #define DELETE 2 typedef struct { int cost; // cost of reaching this cell int parent; // parent cell }cell; cell m[MAXLEN+1][MAXLEN+1]; // dynamic programming table // 代价函数 int match(char c,char d); int indel(char c); // 初始化与目标格 void row_init(int i); void column_init(int i); void goal_cell(char *s,char *t,int *i,int *j); // 编辑距离 int string_compare(char *s,char *t); // 相似度判定 bool same(char *s,char *t); int main() { bool ok=false; while(ok==false) { char name[31],serial[31]; name[0]=serial[0]='!'; cout<<"Please input your name:"<<endl; cin>>&name[1]; cout<<"Please input your serial number:"<<endl; cin>>&serial[1]; // cout<<strlen(name)<<" "<<strlen(serial)<<endl; // cout<<string_compare(name,serial)<<endl; if( strlen(name)>=4 && ( strlen(name)==strlen(serial) ) && same(name,serial) && string_compare(name,serial)==5 ) { ok=true; cout<<"Congratulations!"<<endl; cout<<endl; } else { cout<<"Sorry!"<<endl; cout<<endl; } } system("PAUSE"); return 0; system("PAUSE"); return 0; } int match(char c,char d) { if(c==d) return 0; else return 1; } int indel(char c) { return 1; } void row_init(int i) { m[0][i].cost=i; if(i>0) m[0][i].parent=INSERT; else m[0][i].parent=-1; } void column_init(int i) { m[i][0].cost=i; if(i>0) m[i][0].parent=DELETE; else m[0][i].parent=-1; } void goal_cell(char *s,char *t,int *i,int *j) { *i=strlen(s)-1; *j=strlen(t)-1; } int string_compare(char *s,char *t) { int i,j,k; // counter int opt[3]; // cost of the three options for(i=0;i<MAXLEN;i++) { row_init(i); column_init(i); } for(i=1;i<strlen(s);i++) { for(j=1;j<strlen(t);j++) { opt[MATCH]=m[i-1][j-1].cost+match(s[i],t[j]); opt[INSERT]=m[i][j-1].cost+indel(t[j]); opt[DELETE]=m[i-1][j].cost+indel(s[i]); m[i][j].cost=opt[MATCH]; m[i][j].parent=MATCH; for(k=INSERT;k<=DELETE;k++) { if(opt[k]<m[i][j].cost) { m[i][j].cost=opt[k]; m[i][j].parent=k; } } } } goal_cell(s,t,&i,&j); return m[i][j].cost; } bool same(char *s,char *t) { // 相似度小于50%,返回true int count=0; for(int i=1;i<strlen(s);i++) { if(s[i]==t[i]) count++; } if(count<=strlen(s)/2) return true; else return false; } |
|
[求助]为何这种优化有效?
这个学习了。 不过这样有个疑问: 1,楼主的测试方法确实可能会出现线程调度。(或者说一定出现了线程调度) 2,在您的测试方法中并没有解决掉线程调度这一问题,在两个rdstc之间还是会出现线程调度。(中间有循环,可能某次循环或某次指令后,CPU分配的时间片用完之后,就会发生线程调度) 混乱中。 继续关注。 疑问:到底这是不是个优化? ……………………坐等高手结贴。……………… |
|
|
|
[求助]为何这种优化有效?
1,一般的流水计算机只有一条指令流水线,所以称为标量流水计算机。所谓超标量流水,是指它具有两条以上的指令流水线。 2,如果不采用流水线,一条指令要 取指令-》指令译码-》执行运算-》结果写回;然后才能再取指令-》指令译码-》…… (一个时间一个动作) 如果采用标量流水线的话,可流水执行一条指令(流水处理部件)。 (时间并行优势) 如果是超标量流水(2条或更多),可以流水执行2条指令。 (空间并行优势)(参照3) 3,比如Pentium系统结构核心,其有两条指令流水线。假如是U和V两条指令流水线,每条流水线都有自己的ALU、地址生成电路、与数据cache的接口。这样的话,两条指令如果不是数据相关等,那么CPU就可以流水执行两条指令了。 建议参阅计算机组成原理相关书籍。 ---------流水CPU技术--------- 个人理解如此,可以探讨,我对这本帖也十分关注。这个效率提高,有点意思…… 要期末考,计算机组成原理,汇编,网络…… ⊙﹏⊙b汗 |
|
[求助]为何这种优化有效?
猜测一下: 1,CPU超标量流水线处理技术。(时间并行与空间并行) 2,改进前:各指令具有数据相关性,几乎不能利用超标量流水线 改进后:在每次i循环开始时,可以同时执行两条指令(两条流水线),即外层每一次循环时,inc i和mov j,0可以并行执行,于是节约了微小的时间。 3,大胆估计:约节约1000条指令的时间。 -------------参考:《计算机组成原理》------------- 坐等高手斧正。 |
|
|
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值