对于本次作业:

我的整体思路如下:

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. 用matlab训练数字分类的深度神经网络Training a Deep Neural Network for Digit Classification

    This example shows how to use Neural Network Toolbox™ to train a deep neural network to classify ima ...

  2. Python中的 isdigit()方法

    Python isdigit()方法 sdigit()方法就是检测字符串是否只有数字组成, 如果字符串中是只有数字组成,则返回true, 如果字符串中有其他字符,则返回false. 语法格式是:  s ...

  3. android从应用到驱动之—camera(2)---cameraHAL的实现

    本来想用这一篇博客把cameraHAL的实现和流程都给写完的.搞了半天,东西实在是太多了.这篇先写cameraHAL的基本实现框架,下一篇在具体写camerahal的流程吧. cameraHAL的实现 ...

  4. EXC_BAD_ACCESS

    EXC_BAD_ACCESS,就可以在控制台中看到是哪个对象被释放掉了. 另外要避免频繁的出现上述问题,下面是一些建议: 1. 当引用了别人传递进来的对象时,最好retain一下,避免在别人那里已经把 ...

  5. oracle Instance status: READY–lsnrctl status|start|stop

    监听器启动,并不一定会认识数据库实例,启动监听器,请判别相关实例是否 READY [oracle@redhat4 ~]$ lsnrctl status LSNRCTL for Linux: Versi ...

  6. Android开发之通过反射获取到Android隐藏的方法

    在PackageManger中,有些方法被隐藏了,无法直接调用,需要使用反射来获取到该方法. 比如方法:getPackageSizeInfo(),通过这个方法可以获取到apk的CacheSize,Co ...

  7. linux制作livecd

    执行: $sudo cp /home/jxg/backup-2011.01.05/backup2011.01.05.squashfs /home/jxg/livecd/casper/filesyste ...

  8. 自定义View等待旋转

    效果图 1 string.xml <string name="default_progressbar">Default Progressbar:</string& ...

  9. UVA 10537 The Toll! Revisited uva1027 Toll(最短路+数学坑)

    前者之所以叫加强版,就是把uva1027改编了,附加上打印路径罢了. 03年的final题哦!!虽然是水题,但不是我这个只会做图论题的跛子能轻易尝试的——因为有个数学坑. 题意:运送x个货物从a-&g ...

  10. 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)

    本文记录OpenGL播放视频的技术.上一篇文章中,介绍了一种简单的使用OpenGL显示视频的方式.但是那还不是OpenGL显示视频技术的精髓.和Direct3D一样,OpenGL更好的显示视频的方式也 ...