資源簡介
窮舉法解決背包問題,想要資源的一看題目就知道,不需要多花字數(shù)來介紹
代碼片段和文件信息
#include?“Knap.h“
Knap::Knap(char?*in?char?*out):fout(out)
{
ifstream?fin(in);
if?(!fin)
{
cout< exit(0);
}
fin>>c>>n;
if?(n>32?||?n<=0)
{
cout<<“n(=“< fin.close();
exit(0);
}
w?=?new?float[n+1];
p?=?new?float[n+1];
if?(!w?||?!p)?
{
cout<<“內(nèi)存分配失敗!“< fin.close();
exit(0);
}
for?(int?i=1;?i<=n;?i++)
fin>>w[i];
for?(i=1;?i<=n;?i++)
fin>>p[i];
fin.close();
bestx=0;
bestp=0;
if?(!fout)
{
cout< exit(0);
}
}
void?Knap::Knapsack()
{
unsigned?long?ik;
k=?(1< for?(i=0;i<=k;i++)
check(i);
print();
}
void?Knap::check(unsigned?long?i)
{
float?W=0.0;??//方案i的物品總重量
float?P=0.0;????//方案i的物品總價值
int?j=1;?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4440??2012-02-16?09:34??01背包問題-窮舉法\01背包問題.dsp
?????文件????????545??2012-02-16?09:23??01背包問題-窮舉法\01背包問題.dsw
?????文件??????41984??2012-02-17?09:09??01背包問題-窮舉法\01背包問題.ncb
?????文件??????48640??2012-02-17?09:09??01背包問題-窮舉法\01背包問題.opt
?????文件????????254??2012-02-17?08:44??01背包問題-窮舉法\01背包問題.plg
?????文件?????????33??2009-02-18?11:00??01背包問題-窮舉法\1input.txt
?????文件?????????14??2012-02-16?10:20??01背包問題-窮舉法\1output.txt
?????文件?????????47??2011-01-13?17:16??01背包問題-窮舉法\5_1_output.txt
?????文件?????561252??2012-02-17?08:39??01背包問題-窮舉法\Debug\01背包問題.exe
?????文件?????835324??2012-02-17?08:39??01背包問題-窮舉法\Debug\01背包問題.ilk
?????文件?????186972??2012-02-16?09:44??01背包問題-窮舉法\Debug\01背包問題.pch
?????文件????1467392??2012-02-17?08:39??01背包問題-窮舉法\Debug\01背包問題.pdb
?????文件?????365669??2012-02-17?08:39??01背包問題-窮舉法\Debug\Knap.obj
?????文件??????98766??2012-02-16?10:48??01背包問題-窮舉法\Debug\main.obj
?????文件??????91136??2012-02-17?08:44??01背包問題-窮舉法\Debug\vc60.idb
?????文件?????118784??2012-02-17?08:39??01背包問題-窮舉法\Debug\vc60.pdb
?????文件????????104??2012-02-16?10:12??01背包問題-窮舉法\input.txt
?????文件???????1219??2012-02-17?08:39??01背包問題-窮舉法\Knap.cpp
?????文件????????631??2012-02-16?10:48??01背包問題-窮舉法\Knap.h
?????文件????????124??2012-02-16?10:37??01背包問題-窮舉法\main.cpp
?????文件?????????46??2012-02-17?08:44??01背包問題-窮舉法\output.txt
?????目錄??????????0??2012-07-10?20:20??01背包問題-窮舉法\Debug
?????目錄??????????0??2012-07-10?20:20??01背包問題-窮舉法
-----------?---------??----------?-----??----
??????????????3823376????????????????????23
- 上一篇:ARM嵌入式系統(tǒng)源程序-華容道
- 下一篇:計算機端口入侵詳細講解教程
評論
共有 條評論