对于本次作业:

我的整体思路如下:

1、首先修改二维数组求最大子数组和的C语言代码,加入分步骤的当前最优解边界值,局部最优解的记录,使之支持分步执行,连续执行,回滚等功能。

2、将程序改写为Javascript嵌入到HTML中,并进行呈现。

1、依据原有搜索和动态规划算法,记录每一步骤选定的line和column边界值,当前最大子数组和的值。

  

line和column边界值由linea,lineb,linex,liney 记录

max记录每一步的局部最优解。

输入时加入mode选择,控制连续执行还是单步执行。

 #include <stdio.h>
#include <dos.h>
//Part_define
int n,m;
long long max=-,data[][];
int sum=;
void Part_intput();
void Part_function(int mode);
void Part_output();
int main()
{
int mode;
printf("Welcome to our programme! Here I gonna show you this,for a two-dimensional array,how the maximum of sub-array's sum is calculated!\n");
printf("First comes the input part:\n");
Part_intput(); printf("You can choose different modes, \nMode 1 for viewing the process step by step~! \nMode 2 for viewing it uninterrupted~!\n");
while()
{
printf("Please choose your mode 1/2?");
scanf("%d",&mode);
if(mode!= && mode !=)printf("Your mode number is illegal.\n");
else break;
}
printf("\n"); Part_function(mode);
Part_output();
return ;
}
void Part_intput()
{
int i,j;
printf("Please enter the number of lines: ");
scanf("%lld",&m);
printf("and the number of columns: ");
scanf("%lld",&n);
printf("then the elements of the array:\n"); for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
scanf("%lld",&data[i][j]);
}
}
}
void Part_function(int mode)
{
int i,j,k,l,linex,liney,linea,lineb;
char o;
long long f[][]={},columnsum[]={};
linex=;liney=,linea=,lineb=;
for(k=;k<=m;k++)
{
for(l=k;l<=m;l++)
{ for(i=;i<=n;i++){columnsum[i]=;f[][i]=;f[][i]=;} for(i=;i<=n;i++){
for(j=k;j<=l;j++){
columnsum[i]+=data[j][i];
}
}
f[][]=columnsum[];f[][]=columnsum[]; for(i=;i<=n;i++){
if(f[][i-]+columnsum[i]>=f[][i-] && f[][i-]+columnsum[i]>=columnsum[i]){f[][i]=f[][i-]+columnsum[i];liney=i;}
if(f[][i-]+columnsum[i]<=f[][i-] && f[][i-]>=columnsum[i])f[][i]=f[][i-];
if(f[][i-]+columnsum[i]<=columnsum[i] && f[][i-]<=columnsum[i]){f[][i]=columnsum[i];linex=i;liney=i;}
if(f[][i-]>=)f[][i]=f[][i-]+columnsum[i];
else {f[][i]=columnsum[i];}
}
if(max<=f[][n]){max=f[][n];linea=k,lineb=l;}
printf("The current maximum domain of sub-array is from Line %d to Line %d, from Column %d to Column %d\n",linea,lineb,linex,liney);
printf("The current maximum value of sub-array is :%d\n",max);
if(mode==)
{
printf("Next Step? Y/N\n");
while()
{ scanf("%c",&o);
if(o=='Y')break; }
}
else {sleep();} }
}
//f[0][i]=f[1][i-1]+a[i] f[0][i-1] a[i];
//f[1][i]=f[1][i-1]+a[i] a[i]
} void Part_output()
{
printf("The maximum value of sub-array is :%d\n",max);
system("pause"); }
/*
3
6
5 6 -3 8 -9 2
1 -12 20 0 -3 -5
-9 -7 -3 6 7 -1
*/

运行结果如下:

顺利完成。

2、由于之前对于HTML,JAVASCRIPT之前了解不是很多。正在学习中,预计这两天将程序改善并更新,届时再给出总结所花费的时间和估计,以及总结等等。

Homework-10 BASIC的更多相关文章

  1. Part 1 to 10 Basic in C#

    Part 1 Introduction The struct of C# program: namespace , class and Main method what is namespace? t ...

  2. Bank homework 10 2016 4 25

    #include<iostream>#include<string>using namespace std;class Bank { public: Bank(string _ ...

  3. Cheatsheet: 2013 10.09 ~ 10.23

    Other 10 Basic Linux Networking and Monitoring Commands You Should Know A simple, portable yet effic ...

  4. Python 入门教程 10 ---- Student Becomes the Teacher

    第一节 1 练习 1 设置三个的字典分别为lloyd,alice,tyler 2 对每一个的字典的key都设置为"name","homework" , &quo ...

  5. MSDS 596 Homework

    MSDS 596 Homework 10 Due November 28 2017Notes. The lowest grade among all eleven homework will be d ...

  6. Flask Web开发从入门到放弃(一)

    第1章 章节一 01 内容概要 02 内容回顾 03 路飞学城之加入购物车 04 路飞学城之结算 05 路飞学城之立即支付 06 路飞学城之后续计划 07 Flask框架简介和快速使用 08 FLas ...

  7. 上海交大课程MA430-偏微分方程续论(索伯列夫空间)之总结(Sobolev Space)

    我们所用的是C.L.Evans "Partial Differential Equations" $\def\dashint{\mathop{\mathchoice{\,\rlap ...

  8. c++(基数排序)

    基数排序是另外一种比较有特色的排序方式,它是怎么排序的呢?我们可以按照下面的一组数字做出说明:12. 104. 13. 7. 9 (1)按个位数排序是12.13.104.7.9 (2)再根据十位排序1 ...

  9. 【深度学习】Pytorch 学习笔记

    目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...

  10. 使用Maven命令行快速创建项目骨架(archetype)

      > mvn archetype:generate 接下来就会输出一些列带索引变化的archetype项可供我们选择,然后提示我们选择一个编号,可以直接回车选择默认的编号(392),然后就跟着 ...

随机推荐

  1. 【POJ】2170 Lattice Animals

    1. 题目描述给定$n \times m, n.m \in [1, 10]$的方格,求不同形状的$[1 \cdots 10]$联通块的个数?所谓不同形状,表示不能通过平移.旋转.镜像实现相同的形状.2 ...

  2. [HDOJ4612]Warm up(双连通分量,缩点,树直径)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 所有图论题都要往树上考虑 题意:给一张图,仅允许添加一条边,问能干掉的最多条桥有多少. 必须解决 ...

  3. mysql定时计划任务,ON COMPLETION [NOT] PRESERVE 当单次计划任务执行完毕后或当重复性的计划任务执行到了ENDS阶段。而声明PRESERVE的作用是使事件在执行完毕后不会被Drop掉

    当为on completion preserve 的时候,当event到期了,event会被disable,但是该event还是会存在当为on completion not preserve的时候,当 ...

  4. UVa 11489 (博弈) Integer Game

    一个数字能被3整除就等价于这个数的各个数字之和被3整除. 所以一开始的时候先要拿一个能使剩下的数字是3的倍数的数. 然后就一直拿0.3.6.9直到某人不能再拿为止. #include <cstd ...

  5. Ajax、Comet与Websocket

    从 http 协议说起 1996年IETF  HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式 ...

  6. 一天一个Java基础——对象和类

    1.在Java中你所做的全部工作就是定义类,产生那些类的对象,以及发送消息给这些对象 2.可以在类中设置两种类型的元素:字段(也被称作数据成员)和方法(也被称作成员函数) 3.字段可以是任何类型的对象 ...

  7. HTML5之video元素

    一.video元素支持的视频格式 HTML5中的video标签支持3种常用的视频格式: 1.Ogg = 带有Theora 视频编码和Vorbis 音频编码的 Ogg 文件: 2.MPEG4 = 带有H ...

  8. android bin目录下的.ap_是神马文件?

    resources.ap_ resources翻译过来是资源的意思 应该就是一种中间文件,可以改成rar.zip等压缩文件的类型,里面包含res.AndroidMainfest.xml.resourc ...

  9. Oracle的OracleBulkCopy不支持事务处理

    在进行OracleBulkCopy批量数据导入的过程中使用事务后抛出了异常, 没使用事务时可以正确批量导入, ORA-12154:无法解析指定的连接字符串, 但是TNS配置肯定是没有错的, 难道是Co ...

  10. 走向DBA[MSSQL篇] - 从SQL语句的角度提高数据库的访问性能(转)

    最近公司来一个非常虎的DBA,10几年的经验,这里就称之为蔡老师吧,在征得我们蔡老同意的前提下 ,我们来分享一下蔡老给我们带来的宝贵财富,欢迎其他的DBA来拍砖.  目录 1.什么是执行计划?执行计划 ...