京东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;

}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页