作者:zhizhong
接收于5月15日 晚11:20
本次唯一一篇程序作品
正文:
/**
*@author:KF.Peng
*@date:2019.06.15
*history:
*1.create
*/
#include<stdio.h>
#include<stdlib>
int V[100][100];
int max(int a, int b)
{
if (a >= b)
return a;
else return b;
}
int fmb(int n, int w[], int v[], int s[], int C)
{
int i, j;
for (i = 0; i <= n; i++)
V[i][0] = 0;
for (j = 0; j <= C; j++)
V[0][j] = 0;
for (i = 0; i < n; i++){
for (j = 0; j < C+1; j++){
if (j<w[i])
V[i][j] = V[i - 1][j];
else
V[i][j] = max(V[i - 1][j], V[i - 1][j - w[i]] + v[i]);
}
}
return V[n - 1][C];
}
int main(int argc, char *argv[])
{
int x;
int w[8] = {3,2,6,5,4,2,3,1};
int v[8] = {1,5,4,6,3,5,4,6};
int s[8];
int n = 8;
int C=16;
x = fmb(n, w, v, s, C);
printf("孩子:\n");
printf(“粽子:\n”)
printf("程序:%d\n", x);
system("pause");
return 0;
}
网友评论