




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
动态规划实验实验二:在=a,b,c上定义乘法:abcabbabcbacacc若x = x1x2.xn 是上的乘法运算表达式。则x存在多少种可能的运算顺序,其结果均为a.动态规划算法所解问题的基本特征:1、 最优子结构性质2、 子问题重叠性质分析:上的任意串x = x1x2.xn ,有多少种可能的计算顺序使x = a.设子问题:xij = xixi+1.xkxk+1.xj ,它有 mij0种不同的计算顺序,使得xij = amij1种不同的计算顺序,使得xij = bmij2种不同的计算顺序,使得xij = c(其中0代表a,1代表b,2代表c)1xi = a & i=jmij0=0xi != a & i=j(k=i,j-1)(mik0*mk+1j2+mik1*mk+1j2+mik2*mk+1j0)(k=i,j-1):“k=i”在的下方,“j-1”在的上方)package dynamic_programming;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;public class MultiplicationTable private static String str = null;public static void main(String args) InputStream inputStream = System.in;InputStreamReader inputStreamReader = new InputStreamReader(inputStream);BufferedReader bufferedReader = new BufferedReader(inputStreamReader);tryout: while(true)System.out.print(Please input a string: );if(str = bufferedReader.readLine().length() = 0)System.out.println(Empty Input! );continue;for(char ch : str.toCharArray()if(ch c | ch a)System.out.println(Illegal Input! input among a, b or c);continue out;break;catch(IOException e)e.printStackTrace();int n = str.length();int a = new intnn3;/intialize the arrayfor(int i = 0; i n; i+)for(int j = 0; j n; j+)for(int k = 0; k 3; k+)aijk = 0;/get info from the given string for(int i = 0; i n; i+)aiistr.charAt(i) - a = 1;/here 0:a, 1:b, 2:c for(int s=0;sn;s+) for(int v=0;vn;v+) /System.out.print(asv0+ ); /System.out.println(); /System.out.println(b啊啊啊啊啊); for(int s=0;sn;s+) for(int v=0;vn;v+) /System.out.print(asv1+ ); /System.out.println(); /System.out.println(c啊啊啊啊啊); for(int s=0;sn;s+) for(int v=0;vn;v+) /System.out.print(asv2+ ); /System.out.println(); for(int k = 1; k n; k+) /the length of a pair of brackets from 1 to n - 1 for(int i = 0; i n - k; i+) /the position of the first bracket int j = i + k; for(int t = i;t j;t+) /t is the position of the second bracket from i to j - 1 aij0 += ait2 * at+1j0 /c * a = a + ait0 * at+1j2 /a * c = a + ait1 * at+1j2; /b * c = a / System.out.print(aij0=+aij0+t=+t+ +i=+i+ +j=+j+ ); aij1 += ait0 * at+1j0 /a * a = b + ait0 * at+1j1 /a * b = b + ait1 * at+1j1; /b * b = b / System.out.println(bbbbbbbbbbb); / System.out.print(aij1=+aij0+t=+t+ +i=+i+ +j=+j+ ); aij2 += ait1 * at+1j0 /b * a = c + ait2 * at+1j1 /c * b = c + ait2 * at+1j2; /c * c = c / System.out.println(cccccc); / System.out.print(aij2=+aij0+t=+t+ +i=+i+ +j=+j+ ); / System.out.println(); for(int s=0;sn;s+) for(int v=0;vn;v+) System.out.print(asv0+ ); System.out.println(); System.out.println(b啊啊啊啊啊); for(int s=0;sn;s+) for(int v=0;vn;v+) System.out.print(asv1+ ); System.out.println(); System.out.println(c啊啊啊啊啊); for(int s=0;sn;s+) for(int v=0;vn;v+) System.out.print(asv2+ ); System.out.println(); int result=0; for(int s=0;sn;s+) for(int v=0;vn;v+) result+=asv0; / a0n-10 means the number of methods str0 to n-1 which equals a / System.out.println(一共有: + a0n-10+.+result+种可能); System.out.println(一共有: +result+种可能); 程序的执行:输入:cbabca,结果是a有38种可能Please input a string: cbabca0 0 1 0 5 19 0 0 0 0 2 5 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 b啊啊啊啊啊0 0 0 1 1 6 0 1 0 1 1 4 0 0 0 1 1 2 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 c啊啊啊啊啊1 1 1 4 8 17 0 0 1 1 2 5 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 一共有: 38种可能输入:bcabca,结果是a有37种可能Please input a string: bcabca0 1 0 1 7 14 0 0 1 0 2 5 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 b啊啊啊啊啊1 0 1 3 3 15 0 0 0 1 1 3 0 0 0 1 1 2 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 c啊啊啊啊啊0 0 1 1 4 13 0 1 0 1 2 6 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 一共有: 37种可能输入:acbabba,结果是a有108种可能1 1 1 2 5 14 49 0 0 0 1 0 0 23 0 0 0 0 0 0 6 0 0 0 1 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 b啊啊啊啊啊0 0 1 2 8 26 51 0 0 0 0
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年飞机系统试题及答案
- 2025年闸门运行工(高级)职业技能考试题及答案
- XJJT 096-2018 农村厕所粪污处理技术规程
- 免疫治疗公平性研究-洞察及研究
- 安财管理学考试题及答案
- 阿克苏兵团公务员考试题及答案
- 出差人员工作绩效评价与激励合同
- 工程机械运输合同含设备拆解、运输及重组服务
- 酒店管理权转让及经营合同范本
- 2025公务员选拔面试题及答案
- 第08讲+建议信(复习课件)(全国适用)2026年高考英语一轮复习讲练测
- 2024广东省产业园区发展白皮书-部分1
- 2025年国家网络安全宣传周网络安全知识考核试题
- 2025四川蜀道建筑科技有限公司招聘16人备考练习题库及答案解析
- 2025秋部编版(2024)八年级上册语文上课课件 第三单元 阅读综合实践
- 借车给他人免责协议书
- 任务一切中断时的接发列车办法授课颜保凡课件
- 情侣合伙开店合同范例
- 800 稳定大底
- 金属结构制造与安装-第七章平板钢闸门的安装ppt课件
- 保护性约束技术操作流程
评论
0/150
提交评论