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),然后就跟着 ...
随机推荐
- 随机森林——Random Forests
[基础算法] Random Forests 2011 年 8 月 9 日 Random Forest(s),随机森林,又叫Random Trees[2][3],是一种由多棵决策树组合而成的联合预测模型 ...
- maven小项目注册服务(三)--web模块
java的web应用打包方式一般为war它和jar的区别就是包含了更多的资源和文件,如JSP文件,静态资源文件,servlet等等.war包的核心就WEB-INF文件夹下必须有一个web.xml 的配 ...
- command-t插件使用说明
类似于SourceInsight的Project Window,快速浏览项目里的文件 \t或:CommandT打开该插件 g:CommandTTraverseSCM设置搜索工程的根目录 tab在提示窗 ...
- Oracle 数据集成的实际解决方案
就针对市场与企业的发展的需求,Oracle公司提供了一个相对统一的关于企业级的实时数据解决方案,即Oracle数据集成的解决方案.以下的文章主要是对其解决方案的具体描述,望你会有所收获. Oracle ...
- [Codeforces676B]Pyramid of Glasses(递推,DP)
题目链接:http://codeforces.com/problemset/problem/676/B 递推,dp(i, j)表示第i层第j个杯子,从第一层开始向下倒,和数塔一样的题.每个杯子1个时间 ...
- 分解成3NF的保持函数依赖的分解算法:
转换成3NF的保持函数依赖的分解算法: ρ={R1<U1,F1>,R2<U2,F2>,...,Rk<Uk,Fk>}是关系模式R<U,F>的一个分解,U= ...
- 设置COOKIE过期时间的方法
第一,日期运算法 1)将期限设置为当前日期后的第N天的0时0分0秒 Response.Cookies(LastView).Expires=dateadd(d,N,date) 2)将期限设置为当前日期后 ...
- hdu 3359 Kind of a Blur (高斯消元 浮点型)
题目链接 题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B ...
- UVa 11572 Unique snowflakes【滑动窗口】
题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostr ...
- LeetCode: MergekSortedLists
Title: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its comple ...