AcWing 5. 代码规范
原题链接
中等
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_backSer(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] >> m_backSer[i];
}
for (int i = 0; i < m_backTotal; ++i)
{
int m_totalSeri = m_backSer[i], m_increment = 1;
while (m_totalSeri >= m_increment)
{
for (int j = m_backVolTotal - m_backVol[i]* m_increment; j >= 0; --j)
{
if (m_backDp[j] + m_backQual[i]*m_increment > m_backDp[m_backVol[i]* m_increment + j])
{
m_backDp[m_backVol[i]* m_increment + j] = m_backDp[j] + m_backQual[i]* m_increment;
}
}
m_totalSeri -= m_increment;
m_increment = m_increment << 1;
}
if (m_totalSeri > 0)
{
for (int j = m_backVolTotal - m_backVol[i] * m_totalSeri; j >= 0; --j)
{
if (m_backDp[j] + m_backQual[i] * m_totalSeri > m_backDp[m_backVol[i] * m_totalSeri + j])
{
m_backDp[m_backVol[i] * m_totalSeri + j] = m_backDp[j] + m_backQual[i] * m_totalSeri;
}
}
}
}
std::cout << m_backDp[m_backVolTotal] << std::endl;
m_backVol.clear();
m_backQual.clear();
m_backSer.clear();
m_backDp.clear();
return 0;
}