




已阅读5页,还剩33页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
算法设计与分析实验报告实验序号: 实验项目名称:编程实现动态规划的算法学号姓名 专业、班 11软服2班实验地点指导教师实验时间2013/11/29一、实验目的及要求 1. 体验实现程序的运行过程 2. 写出源程序,并编译运行。2、 实验内容与步骤 1.矩阵连乘问题(或多边形游戏问题) 2.最长公共子序列问题(或最接近点对问题)3、 实验方法 4、 实验结果与数据处理最长公共子序列:乘法五、分析与讨论对上机实践结果进行分析,上机的心得体会。六、教师评语签名:日期:附源程序清单: 最长公共子序列:Import java.io.BufferedReader; Import java.io.IOException; Import java.io.InputStreamReader; Import java.util.ArrayList; Import java.util.Scanner; Import java.util.List; /* * 动态规划法解最长公共子系列。 * author蓝冠恒 */Public class LcsLength publicstatic List resultList = New ArrayList(); /* * 计算最优值 * param x * 字符系列数组 * param y * 字符系列数组 * param c * 存储x和y最长公共子系列长度数组 * param b * 记录c中元素对应子问题的解的数组 */ public static void lcsLength(char x, char y, int c, int b) int m = x.length - 1; int n = y.length - 1; resultList.clear(); for (int i = 1; i = m; i+) ci0 = 0; for (int i = 1; i = n; i+) c0i = 0; for (int i = 1; i = m; i+) for (int j = 1; j = cij - 1) cij = ci - 1j; bij = 2; else cij = cij - 1; bij = 3; public static void lcs(int i, int j, char x, int b) if (i = 0 | j = 0) return; if (bij = 1) lcs(i - 1, j - 1, x, b); resultList.add(xi); else if (bij = 2) lcs(i - 1, j, x, b); else lcs(i, j - 1, x, b); publicstaticvoid main(String arg) String a; String input; char x; char y; Scanner scan= New Scanner(System.in); BufferedReader in = New BufferedReader(New InputStreamReader(System.in); do try do System.out.println(请输入第一串字符系列); input = in.readLine().trim(); while(input.equals(); input = S + input; x = input.toCharArray(); do System.out.println(请输入第二串字符系列); input = in.readLine().trim(); while (input.equals(); input = S + input; y = input.toCharArray(); int b = newintx.lengthy.length;int c = New intx.lengthy.length; lcsLength(x, y, c, b);/ 计算最优值lcs(x.length- 1, y.length- 1, x, b);/ 构造最长公共子系列int size = resultList.size(); System.out.print(最长公共子系列为:); for(int i = 0; i size; i+) System.out.print(resultList.get(i); System.out.println(n); catch (IOException e) e.printStackTrace(); System.out.print(继续输入请按y。退出请按任意键!); a=scan.nextLine(); while (a.equals(y); 连乘问题 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; import java.util.List; /* * 动态规划法解最长公共子系列。 * author 蓝冠恒 */ public class LcsLength public static List resultList = new ArrayList(); /* * 计算最优值 * param x * 字符系列数组 * param y * 字符系列数组 * param c * 存储x和y最长公共子系列长度数组 * param b * 记录c中元素对应子问题的解的数组 */ public static void lcsLength(char x, char y, int c, int b) int m = x.length - 1; int n = y.length - 1; resultList.clear(); for (int i = 1; i = m; i+) ci0 = 0; for (int i = 1; i = n; i+) c0i = 0; for (int i = 1; i = m; i+) for (int j = 1; j = cij - 1) cij = ci - 1j; bij = 2; else cij = cij - 1; bij = 3; public static void lcs(int i, int j, char x, int b) if (i = 0 | j = 0) return; if (bij = 1) lcs(i - 1, j - 1, x, b); resultList.add(xi); else if (bij = 2) lcs(i - 1, j, x, b); else lcs(i, j - 1, x, b); public static void main(String arg) String a; String input; char x; char y; Scanner scan= new Scanner(System.in); BufferedReader in = new BufferedReader(new InputStreamReader(System.in); do try do System.out.println(请输入第一串字符系列); input = in.readLine().trim(); while (input.equals(); input = S + input; x = input.toCharArray(); do System.out.println(请输入第二串字符系列); input = in.readLine().trim(); while (input.equals(); input = S + input; y = input.toCharArray(); int b = new intx.lengthy.length; int c = new intx.lengthy.length; lcsLength(x, y, c, b);/ 计算最优值 lcs(x.length- 1, y.length- 1, x, b);/ 构造最长公共子系列int size = resultList.size(); System.out.print(最长公共子系列为:); for (int i = 0; i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年江西省卫生系统招聘考试(中医学)历年参考题库含答案详解
- 2025年北京银行长沙分行社会招聘考试备考题库及答案解析
- 节能监察理论知识培训课件
- 2025年小微企业创业扶持资金申请政策解读与创业团队知识管理报告
- 良好的公共秩序课件
- 教师招聘之《幼儿教师招聘》模拟题库附参考答案详解【培优】
- 教师招聘之《小学教师招聘》能力提升B卷题库附答案详解(巩固)
- 2025呼伦贝尔海拉尔区建设街道办事处招聘城镇公益性岗位人员笔试备考及答案详解(名师系列)
- 教师招聘之《小学教师招聘》能力检测【典优】附答案详解
- 基于2025年电竞游戏用户社交需求的社区运营模式创新报告
- 2025-2026学年人民版小学劳动技术六年级上册教学计划及进度表
- 新学期三年级班主任工作计划(16篇)
- 接种疫苗预防流感课件
- 游戏体验寻规律(教学设计)-2024-2025学年人教版(2024)小学信息技术五年级全一册
- 基于plc的恒压供水控制系统设计
- 环保设备加工处理方案(3篇)
- 《成人重症监护病房口腔护理专家共识》解读课件
- 2025中小学生法制知识竞赛题库及答案
- 恶性间皮瘤护理查房
- 2025新版劳动合同范本
- 喷锚支护施工技术
评论
0/150
提交评论