2017 360php笔试题,2018年360春招笔试编程题第二题

解题思路:背包问题变种

详解思路:

https://blog.csdn.net/u014328804/article/details/79776518

示例代码:

#include

#include

using namespace std;

int a[8][3] = { {0, 0, 0}, {0, 1, 2}, {0, 2, 1}, {1, 1, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0} };

int getNum(int r, int g, int b)

{

vector>>> mat(8, vector>>(r+1, vector>(g+1, vector(b+1, 0))));

for (int i = 1; i < 8; ++i)

{

for (int j = r; j >= 0; j--)

{

for (int n = g; n >= 0; n--)

{

for (int m = b; m >= 0; m--)

{

int t1 = a[i][0] == 0 ? INT_MAX : j / a[i][0];

int t2 = a[i][1] == 0 ? INT_MAX : n / a[i][1];

int t3 = a[i][2] == 0 ? INT_MAX : m / a[i][2];

int bound = (t1 < t2) ? t1 : t2;

bound = (bound < t3) ? bound : t3;

int t4 = mat[i - 1][j][n][m];

for (int k = 1; k <= bound; ++k)

{

int t5 = mat[i - 1][j - k*a[i][0]][n - k*a[i][1]][m - k*a[i][2]] + k;

t4 = (t4 > t5) ? t4 : t5;

}

mat[i][j][n][m] = t4;

}

}

}

}

return mat[7][r][g][b];

}

int main()

{

int num;

int r, g, b;

cin >> num;

while (num > 0)

{

cin >> r >> g >> b;

cout << getNum(r, g, b) << endl;

num--;

}

system("pause");

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值