首页 > 编程语言 >COMP3023动态编程

COMP3023动态编程

时间:2023-05-13 19:55:39浏览次数:30  
标签:txt .- lib 编程 file cpp COMP3023 main 动态


COMP3023 23S Programming Assignment
Lecture 10 introduces the dynamic programming algorithm for the 0-1 knapsack problem. In
this programming assignment, you need to implement the algorithm under the following
requirements.
Environment
- The implementation must be done in standard C or C++ (using gcc/g++ compiler).
Please do not use visual studio. For the students who do not have the compiler, you can
use online GDB at https://www.onlinegdb.com/.
- The submissions which cannot pass gcc/g++ compiling, will directly receive 0. To
check whether your code can pass compiling, use online GDB at least.
Implementation Structure
In your program,
代做COMP3023 you need to implement three source files “main.c”, “lib.h”, and “lib.c”
(“main.cpp”, “lib.h” and “lib.cpp” if you use C++).
For “main.c” (or “main.cpp”)
- It only contains the “main” function.
- It reads inputs from .txt files. The input txt file is passed to the main function as an
argument.
- Each txt file contains exactly one instance.
For “lib.h” and “lib.c” (or “lib.h” and “lib.cpp”)
- .h is the header file for .c (or .cpp).
- They contain all other functions except “main”.
Functionality
- The input txt file has 3 lines. The first line has only one integer, the capacity of the bag.
The second line has a bunch of positive integers for the value of each item. Two integers
are separated by a comma “,”. The third line is in the same format as the second for the
weight of each item.
- When the calculation is finished, print the optimal value and optimal solution(s) one
for each line on the screen. (The optimal value is unique, but the optimal solution may
not.)
- Sort the items in the optimal solution(s) in the decreasing order of item indices.
- The index of items starts from 1.
Sample:
In the folder “Sample”, you will find all the source files described above. Take the C version
in subfolder “c” for example (the C++ version is in subfolder “c++”). Currently, all source files
are empty. The main function simple prints the argument on the screen. “lib.c” only tests the
linkage. The package also contains “make.bat”. You can open it by a TXT editor. Then, you
can see the compilation commands.
After executing “make.bat” (Note that .bat files are only executable in Windows), you will have
“knapsack.exe”.
Suppose the input txt file is named as “in.txt”, we execute “knapsack in.txt”.
We see that “in.txt” is printed and “lib.h” and “lib.c” are tested.
Example instance
Suppose the input file (in1.txt) contains
10
3,5,2,6
3,4,2,5
When you finished, the output should be something like
Because

标签:txt,.-,lib,编程,file,cpp,COMP3023,main,动态
From: https://www.cnblogs.com/wolfjava/p/17398047.html

相关文章

  • zookeeper总结-动态添加节点
    1.比如现在有zk服务节点node1,node2,node3;之前自己一直以为是直接在node4上配置node1,node2,node3,node4的cluster地址,然后启动node4的zk服务,然后node4的zk服务就能加入到node1,node2,node3这个zk集群里;现在发现不行,node4启动后客户端无法连接上去,它也不会同步node1/node2/node......
  • 欧姆龙CP1H模拟量FB功能块实用程序 功能块便于复杂的编程
    欧姆龙CP1H模拟量FB功能块实用程序功能块便于复杂的编程设备反复使用,节约时间并且减少编码错误,使程序更易于理解。本例中以施耐德ATV320变频器为例,使用CP1H自带模拟量功能,模拟量输出0-10v控制两个变频器频率,模拟量输入采集变频器输出4-20ma信号,从而得到实时频率。支持输入断线检测......
  • 说说编程
    什么是编程?什么是编程语言?语言本质就是人与人之间交流的媒介,那么编程语言就是人与计算机之间交流的媒介 编程就是’程序员使用计算机能够读懂的语言(编程语言)把自己的思想用逻辑写出来‘的过程 编程语言的作用是什么?在编程的世界里,计算机就好比是人的奴......
  • C++趣味编程
    折半查找。1#include<iostream>2usingnamespacestd;3#defineN104intmain()5{6inti,a[N]={-3,4,7,9,13,45,67,89,100,180},low=0,high=N-1,mid,k=-1,m;7cout<<"a数组中数据如下"<<endl;8for(inti=0;i<N;i++)......
  • 有趣的动态规划
    原文点此跳转什么是动态规划?动态规划也是算法设计的一种方法/思想。它将一个问题分解为相互重叠的子问题,通过反复求解子问题,来解决原来的问题。基础案例场景一斐波那契数列当前数等于前面两个数的和。定义子问题:f(n)=f(n-1)+f(n-2)原文点此跳转......
  • 代理模式--静态代理+动态代理
    静态代理利用程序实现客户通过中介向房东租房的案例:优缺点理解:代理模式的具体步骤:动态代理同样是以租房为例:需要代理的类是租房的Rent类:Rent.javapackageorg.example.Test;publicinterfaceRent{publicvoidrent();}Host.javapackageorg.example.Te......
  • 编程一小时2023.5.11
    1.#include<iostream>#include<cstring>#include<algorithm>#include<set>usingnamespacestd;constintN=1010;intt,n;inta[N],b[N];set<int>st;intg[N][N];intmain(){scanf("%d",&t);while(t--......
  • 编程一小时2023.5.12
    #include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<unordered_set>#pragmaGCCoptimize(2)#pragmaGCCoptimize(3)#definelfirst#definersecondusingnamespacestd;typedefpair<int,int>......
  • 动态代理
    一、概念什么是代理:如同中介,当一个类不能或不适合直接访问另一个对象时,适合使用。作用:动态代理可以在不更改原类代码的前提下,增强所有类的功能。二、解释(1)角色明星:唱歌、跳舞经纪人:代理明星,表示明星能干什么,来跟老板合作老板:找明星谈合作 (2)静态代理(三个对象)......
  • python软件与编程语言
    编程语言的发展史1.机器语言:计算机内部只认识01二进制数据  #由于计算机是基于电工作的,电是有高低电频之分的,高电频和低电频 优点:执行速度快 缺点:学习难度大2.汇编语言  #用简单的字母表示一串二进制  00011001  a  00001  b  00010  c......