Homework-10 BASIC
对于本次作业:
我的整体思路如下:
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的更多相关文章
- Part 1 to 10 Basic in C#
Part 1 Introduction The struct of C# program: namespace , class and Main method what is namespace? t ...
- Bank homework 10 2016 4 25
#include<iostream>#include<string>using namespace std;class Bank { public: Bank(string _ ...
- Cheatsheet: 2013 10.09 ~ 10.23
Other 10 Basic Linux Networking and Monitoring Commands You Should Know A simple, portable yet effic ...
- Python 入门教程 10 ---- Student Becomes the Teacher
第一节 1 练习 1 设置三个的字典分别为lloyd,alice,tyler 2 对每一个的字典的key都设置为"name","homework" , &quo ...
- MSDS 596 Homework
MSDS 596 Homework 10 Due November 28 2017Notes. The lowest grade among all eleven homework will be d ...
- Flask Web开发从入门到放弃(一)
第1章 章节一 01 内容概要 02 内容回顾 03 路飞学城之加入购物车 04 路飞学城之结算 05 路飞学城之立即支付 06 路飞学城之后续计划 07 Flask框架简介和快速使用 08 FLas ...
- 上海交大课程MA430-偏微分方程续论(索伯列夫空间)之总结(Sobolev Space)
我们所用的是C.L.Evans "Partial Differential Equations" $\def\dashint{\mathop{\mathchoice{\,\rlap ...
- c++(基数排序)
基数排序是另外一种比较有特色的排序方式,它是怎么排序的呢?我们可以按照下面的一组数字做出说明:12. 104. 13. 7. 9 (1)按个位数排序是12.13.104.7.9 (2)再根据十位排序1 ...
- 【深度学习】Pytorch 学习笔记
目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...
- 使用Maven命令行快速创建项目骨架(archetype)
> mvn archetype:generate 接下来就会输出一些列带索引变化的archetype项可供我们选择,然后提示我们选择一个编号,可以直接回车选择默认的编号(392),然后就跟着 ...
随机推荐
- 什么是I帧,P帧,B帧
视频压缩中,每帧代表一幅静止的图像.而在实际压缩时,会采取各种算法减少数据的容量,其中IPB就是最常见的. 简单地说,I帧是关键帧,属于帧内压缩.就是和AVI的压缩是一样的. P是向前搜索的意思.B ...
- MongoDB 安装和即基本操作
http://www.mongodb.org/ Agile and Scalable MongoDB (from "humongous") is an open-source do ...
- trim合理和谐
今天早上,到公司,噩耗传来.上周的上线的功能出现问题,后台mis中有数据不能保存了. 经过紧张的查找,还是我的问题.有一个查重操作,在查重前,会比对新旧值,新值顺手trim了.旧值直接保存了. 在比较 ...
- MySQL select into 和 SQL select into
现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去,虽然可以用以下语句进行复制,总觉得不爽,希望各位帮助下我,谢谢. answer 01: create table d ...
- Asp.Net连接Mysql报错Out of sync with server
Asp.Net连接Mysql报错Out of sync with server 原因:程序引用的MySql.Data.dll版本高于服务器版本 解决:下载一个低版本的MySql.Data.dll,项目 ...
- ASP.NET MVC Html.BeginForm用法1
Html.BeginForm():该方法用于构建一个From表单的开始, 他的构造方法为:Html.BeginForm("ActionName","ControllerN ...
- <pages validateRequest="false"/>在.net4.0中无效的问题
再web.config中设置<pages validateRequest="false"/>在.net4.0中无效的问题 解决方案: <system.web> ...
- mbr grub的区别
mbr是磁盘的物理扇区,不是程序名: 因为BIOS很小,功能有限,为了完成加载操作系统的功能,就产生了mbr: bios检测到一个硬盘后,将硬盘的0柱面.0磁头.1扇区的内容经过简单判断后, 至内存中 ...
- Android 引用library project
1.如何将一个android工程作为库工程(library project) library project是作为jar包被其它android工程使用的,首先它也是普通的android工程.然后: 1 ...
- ylbtech-Model-Account(通用账户模块设计)
ylbtech-DatabaseDesgin:ylbtech-Model-Account(通用账户模块设计) ylbtech-Model-Account(通用账户模块设计) 1.A,数据库关系图(Da ...