AcWing 3. 完全背包问题-代码规范写法
原题链接
简单
C++ 代码
#include<iostream>
#include<vector>
int main()
{
int m_backTotal =0;
int m_backVolTotal = 0;
std::cin>>m_backTotal>>m_backVolTotal;
std::vector<int> m_backVol(m_backTotal);
std::vector<int> m_backQual(m_backTotal);
std::vector<int> m_backDp(m_backVolTotal+1);
for (int i = 0 ; i<m_backTotal; ++i)
{
std::cin>>m_backVol[i]>>m_backQual[i];
}
for (int i = 0 ; i < m_backTotal; ++i)
for (int j =0 ; j<=m_backVolTotal - m_backVol[i] ; ++j)
{
if ( m_backDp[j] +m_backQual[i] > m_backDp[ m_backVol[i] + j])
{
m_backDp[ m_backVol[i] + j] = m_backDp[j] + m_backQual[i];
}
}
std::cout<<m_backDp[m_backVolTotal]<<std::endl;
m_backVol.clear();
m_backQual.clear();
m_backDp.clear();
return 0;
}