梅西迭代算法的实现

这段代码展示了如何用C++实现梅西迭代算法,用于解决线性移位寄存器的综合问题。程序从文件中读取数据,计算并输出产生给定二元序列的最短线性移位寄存器的级数和多项式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
  Name:  梅西迭代算法的实现   
  Copyright: 2003(C)
  Author:  徐岩柏
  Date: 31-10-03 16:09
  Description: 该问题是线性移位寄存器的综合问题提出的,给定一个N长的
               二元序列,如何求出产生这一序列的级数最小的线性移位寄存
               器,即最短的线性移位寄存器
*/

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
  typedef vector<bool> MyArray; file://定义自己的数据类
  MyArray a;   file://状态数组 ,用来保存给定的m序列?
  vector<int>l;   file://线性移位寄存器的级数数组
  MyArray temp;
  vector<MyArray> f; file://为线性移位寄存器对应的多项式
  int N =0;
  ifstream infile("input.txt"); file://从文件中读取数据
  ofstream outfile("output.txt"); file://把结果写入文件中。
  if(!infile)
  {
    cout << "Aata file input.txt is not ready! Please check it"<<endl;
    exit (-1);
  }
  string strTemp;
  infile>>strTemp; file://读入N
 // cout << strTemp <<endl;
  N = atoi(strTemp.c_str());
  infile>>strTemp; file://读入序列
  for( int i = 0 ;i<N; ++i)
  {
     a.push_back(strTemp[i]=='1'); file://把序列保存
  }
 file://cout << strTemp <<endl;
 int n=0;
 l.push_back(0);
 temp.push_back(1); fi

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值