- 浏览: 10205 次
- 性别:
- 来自: 武汉
最新评论
-
wukunlsy:
牛啊,光棍节写的合并程序
Merge(合并两个已排好序的数组) -
wukunlsy:
...
01背包问题
文章列表
合并两个已排好序的数组, Merge算法将会用于下一节的自底向上合并排序算法。
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define Low 0
#define Middle 3
#define High 10
int main(void)
{
int A[High+1] = {2,11,45,57,3,6,13,24,25,65,68};
int B[High+1] = {0,0,0,0,0,0,0,0,0,0,0};
int low = 0;
...
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define N 10
int main(void)
{
int a[N] = {10,9,8,7,6,5,4,3,2,1};
for(int i=0;i<N-1;i++)
{
int k = i;
for(int j=i+1;j<N;j++)
{
if(a[j] < a[k])
k = j; ...
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define N 10
int main(void)
{
int a[N] = {10,9,8,7,6,5,4,3,2,1};
for(int i=1;i<N;i++)
{
int temp = a[i];
int j = i-1;
while(j>=0 && a[j]>temp)
{
a[j+1] = ...
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define Max 255
#define N 3
int main(void)
{
int D[N][N] = {{0,2,9},{8,0,6},{1,Max,0}};
cout<<"Original D is : \n";
for(int i =0;i<N;i++)
{
for(int j=0;j<N;j++)
cout<& ...
#include <stdio.h>
#include <iostream.h>
#define QueenNum 8
void output(int solution[QueenNum])
{
for(int i=0;i<QueenNum;i++)
{
cout<<solution[i]<<" ";
}
cout<<"\n";
}
int judge(int solution[QueenNum])
{
for(int i=0;i<QueenNum;i++)
{
...
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#define A "xyxxzxyzxy"
#define B "zxzyyzxxyxxz"
void output(char str[])
{
for(int i=0;i<strlen(str);i++)
cout<<str[i]<<" ";
cout&l ...
题目:四种类型的物品,体积分别为2,3,5,6,价值分别为4,7,9,11.背包容量为8,每种物品的最大数量不限制
#include <iostream>
using namespace std;
#define MAXSIZE 8
#define NUM 4
int main(void)
{
int size_value[NUM+1][2] = {{0,0},{2,4},{3,7},{5,9},{6,11}};
int solution[NUM+1][MAXSIZE+1];
int v[NUM+1];
for(int p=0;p<= ...
题目:容量为9的背包,有4种物品,体积分别为2,3,4,5,价值分别为3,4,5,7,求能放进背包的最大值。
#include <iostream>
using namespace std;
#define MAXSIZE 9
#define NUM 4
int main(void)
{
int size_value[5][2] = { {0,0},{2,3},{3,4},{4,5},{5,7} };
int solution[NUM + 1][MAXSIZE +1];
for(int p=0;p<=NUM;p++)
{ ...