資源簡介
本個文檔是針對本人算法課實驗講述的一些課程的個人代碼,針對初學者實用性較強,簡單易懂,并且算法體系完備,擁有完備的輸入和輸出。

代碼片段和文件信息
#include
#include
using?namespace?std;
int?V[1000];
int?W[1000];
struct?treenode{
????int?weight;
????int?value;
????int?level;
????int?flag;
????friend?bool?operator(treenode?a?treenode?b)
????{
????????return?a.value?????}
};
priority_queue?prique;
void?enPriQueue(int?weightint?valueint?levelint?flagint?nint*?bestValue)
{
????treenode?node;
????node.weight?=?weight;
????node.value?=?value;
????node.level?=?level;
????node.flag?=?flag;
????if?(level?==?n)
????{
????????if?(value?>?*bestValue)
????????{
????????????*bestValue?=?value;
????????}
????????return;
????}else
????{
????????prique.push(node);
????}
????return;
}
//
int?prioritybbnap(int?w[]int?v[]int?cint?nint*?bestValue)
{
????treenode?liveNode;
????liveNode.weight?=?0;
????liveNode.value?=?0;
????liveNode.level?=?0;
????liveNode.flag?=?0;
????prique.push(liveNode);
????do
????{???
????????if?(liveNode.weight?+?w[liveNode.level]?<=?c)
????????{
????????????enPriQueue(liveNode.weight?+?w[liveNode.level]?liveNode.value?+?v[liveNode.level]
????????????????liveNode.level?+?1?1nbestValue);
????????}
????????enPriQueue(liveNode.weight?liveNode.value?liveNode.level?+?1?0?n?bestValue);
????????liveNode?=?prique.top();
????????prique.pop();
????}?while?(!prique.empty());
????return?0;
}
int?main()
{
????int?n;int?C;
????cout<<“請輸入物品數(shù):“< cin>>n;
cout<<“請輸入背包容量:“< cin>>C;?
cout<<“請輸入物品的重量以及價值(中間用空格分開)“< for(int?m=0;m {
cin>>W[m]>>V[m];
}?
????int?bestValue=0;
????prioritybbnap(W?V?Cn&bestValue);
????cout?<<“裝入的最大價值為:“< ????return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-26?12:01??算法的代碼\
?????文件????????1118??2018-11-19?21:12??算法的代碼\01背包動態(tài).cpp
?????文件?????1912809??2018-11-24?09:52??算法的代碼\01背包動態(tài).exe
?????文件????????1753??2018-11-26?12:00??算法的代碼\01背包分支限界.cpp
?????文件?????2014595??2018-11-26?12:00??算法的代碼\01背包分支限界.exe
?????文件?????????678??2018-10-08?08:50??算法的代碼\二分查找.cpp
?????文件??????392314??2018-11-20?21:26??算法的代碼\二分查找.exe
?????文件????????3328??2018-11-24?09:09??算法的代碼\哈弗曼編碼.cpp
?????文件??????400674??2018-11-24?09:09??算法的代碼\哈弗曼編碼.exe
?????文件?????????824??2018-11-17?16:43??算法的代碼\活動安排問題.cpp
?????文件?????1911090??2018-11-23?22:26??算法的代碼\活動安排問題.exe
?????文件????????1004??2018-11-13?09:04??算法的代碼\矩陣連乘問題.cpp
?????文件?????1912190??2018-11-23?16:16??算法的代碼\矩陣連乘問題.exe
?????文件?????????864??2018-10-08?21:16??算法的代碼\快速排序.cpp
?????文件??????392690??2018-11-21?10:14??算法的代碼\快速排序.exe
?????文件????????1365??2018-11-21?09:21??算法的代碼\棋盤覆蓋.cpp
?????文件??????393037??2018-11-21?09:23??算法的代碼\棋盤覆蓋.exe
?????文件????????1975??2018-11-26?11:58??算法的代碼\未命名2.cpp
?????文件????????1968??2018-10-29?10:25??算法的代碼\線性時間select.cpp
?????文件??????394138??2018-11-21?11:23??算法的代碼\線性時間select.exe
?????文件????????1092??2018-10-29?10:24??算法的代碼\線性時間選擇.cpp
?????文件????????1033??2018-11-14?15:09??算法的代碼\最優(yōu)三角剖分.cpp
?????文件?????1912718??2018-11-23?16:55??算法的代碼\最優(yōu)三角剖分.exe
?????文件????????1120??2018-11-14?13:24??算法的代碼\最長公共子序列問題.cpp
?????文件?????1912893??2018-11-23?20:25??算法的代碼\最長公共子序列問題.exe
評論
共有 條評論