# 京东9-16 多重背包

https://www.cnblogs.com/mfrank/p/10816837.html完全背包、0-1背包、多重背包
https://blog.csdn.net/m0_37830950/article/details/70240661例题

https://www.nowcoder.com/discuss/514943?source_id=profile_create&channel=1009解答
1.道具魅力值
const int len = 10005;
vector infor(len, 0);
int N, V, v, w, s;
int main() {
cin >> N >> V;
for (int i = 0; i < N; i++) {
cin >> s >> v >> w;
for (int j = V; j >= 0; --j) {
for (int k = 1; k <= s && kv <= j; ++k) {
infor[j] = max(infor[j], infor[j - k * v] + k
w);
}
}
}
cout << infor[V];

getchar();
return 0;


}
2.王子走到公主的位置
! !输入字符矩阵的方式 for(int i=0;i<){
for(int j=0;j<)
cin>>c;}
! !判断是否可以走到，是看最后要走到的点是否被标记为""
!! getchar()表示字符输入结束
void dfs(vector<vector>& mat, int i, int j) {
if (i < 0 || i >= mat.size() || j < 0 || j >= mat[0].size() || mat[i][j] == ‘#’ || mat[i][j] == '
’)
return;
mat[i][j] = ‘*’;
dfs(mat, i + 1, j);
dfs(mat, i - 1, j);
dfs(mat, i, j + 1);
dfs(mat, i, j - 1);
}
int main() {

int t, n, m;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n >> m;
int start_x = -1, start_y = -1, end_x = -1, end_y = -1;
vector<vector<char>> mat(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char tmp;
cin >> tmp;
if (tmp == 'E') {
end_x = i;
end_y = j;
}
if (tmp == 'S') {
start_x = i;
start_y = j;
}
mat[i][j] = tmp;
}
}
dfs(mat, start_x, start_y);
if (mat[end_x][end_y] == '*')
cout << "YES" << endl;
else
cout << "NO" << endl;
}
getchar();
return 0;


}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

qq_33761777

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
04-27 3198

01-03 9705
04-15 2191
03-24 51
03-20 64
03-29 26