POJ2353——Ministry

Ministry
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4528 Accepted: 1452 Special Judge

Description

Mr. F. wants to get a document be signed by a minister. A minister signs a document only if it is approved by his ministry. The ministry is an M-floor building with floors numbered from 1 to M, 1<=M<=100. Each floor has N rooms (1<=N<=500) also numbered from 1 to N. In each room there is one (and only one) official.

A document is approved by the ministry only if it is signed by at least one official from the M-th floor. An official signs a document only if at least one of the following conditions is satisfied:
a. the official works on the 1st floor;
b. the document is signed by the official working in the room with the same number but situated one floor below;
c. the document is signed by an official working in a neighbouring room (rooms are neighbouring if they are situated on the same floor and their numbers differ by one).

Each official collects a fee for signing a document. The fee is a positive integer not exceeding 10^9.

You should find the cheapest way to approve the document.

Input

The first line of an input file contains two integers, separated by space. The first integer M represents the number of floors in the building, and the second integer N represents the number of rooms per floor. Each of the next M lines contains N integers separated with spaces that describe fees (the k-th integer at l-th line is the fee required by the official working in the k-th room at the l-th floor).

Output

You should print the numbers of rooms (one per line) in the order they should be visited to approve the document in the cheapest way. If there are more than one way leading to the cheapest cost you may print an any of them.

Sample Input

3 4
10 10 1 10
2 2 2 10
1 10 10 10

Sample Output

3
3
2
1
1

Hint

You can assume that for each official there always exists a way to get the approval of a document (from the 1st floor to this official inclusively) paying no more than 10^9.
This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

Source

Ural Collegiate Programming Contest 1999

dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i][j+1]) + mat[i][j]

方案可以递归输出

#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 510;
const int M = 110;
const int inf = 0x3f3f3f3f;

int dp[M][N], mat[M][N];
int path[M][N];
int m, n, cnt;

void print(int i, int j)/*第i层第j个房间*/
{
	if (i == 1)
	{
		return;
	}
	if (path[i][j] == j)
	{
		print(i - 1, j);
		printf("%d\n", j);
	}
	else if (path[i][j] == j - 1)
	{
		print(i, j - 1);
		printf("%d\n", j - 1);
	}
	else
	{
		print(i, j + 1);
		printf("%d\n", j + 1);
	}
}

int main()
{
	while (~scanf("%d%d", &m, &n))
	{
		memset (dp, inf, sizeof(dp));
		for (int i = 1; i <= m; ++i)
		{
			for (int j = 1; j <= n; ++j)
			{
				scanf("%d", &mat[i][j]);
			}
		}
		for (int i = 1; i <= n; ++i)
		{
			dp[1][i] = mat[1][i];
			path[1][i] = i;
		}
		for (int i = 2; i <= m; ++i)
		{
			for (int j = 1; j <= n; ++j)
			{
				dp[i][j] = mat[i][j] + dp[i - 1][j];
				path[i][j] = j;
			}
			for (int j = 2; j <= n; ++j)
			{
				if (dp[i][j] > dp[i][j - 1] + mat[i][j])
				{
					dp[i][j] = dp[i][j - 1] + mat[i][j];
					path[i][j] = j - 1;
				}
			}
			for (int j = n - 1; j >= 1; --j)
			{
				if (dp[i][j] > dp[i][j + 1] + mat[i][j])
				{
					dp[i][j] = dp[i][j + 1] + mat[i][j];
					path[i][j] = j + 1;
				}
			}
		}
		int ans = inf, s;
		cnt = 0;
		for (int i = 1; i <= n; ++i)
		{
			if (ans > dp[m][i])
			{
				s = i;
				ans = dp[m][i];
			}
		}
		print(m, s);
		printf("%d\n", s);
	}
	return 0;
}


【3D应力敏感度分析拓扑优化】【基于p-范数全局应力衡量的3D敏感度分析】基于伴随方法的有限元分析和p-范数应力敏感度分析(Matlab代码实现)内容概要:本文档介绍了基于伴随方法的有限元分析与p-范数全局应力衡量的3D应力敏感度分析,并结合拓扑优化技术,提供了完整的Matlab代码实现方案。该方法通过有限元建模计算结构在载荷作用下的应力分布,采用p-范数对全局应力进行有效聚合,避免传统方法中应力约束过多的问题,进而利用伴随法高效求解设计变量对应力的敏感度,为结构优化提供关键梯度信息。整个流程涵盖了从有限元分析、应力评估到敏感度计算的核心环节,适用于复杂三维结构的轻量化与高强度设计。; 适合人群:具备有限元分析基础、拓扑优化背景及Matlab编程能力的研究生、科研人员与工程技术人员,尤其适合从事结构设计、力学仿真与多学科优化的相关从业者; 使用场景及目标:①用于实现高精度三维结构的应力约束拓扑优化;②帮助理解伴随法在敏感度分析中的应用原理与编程实现;③服务于科研复现、论文写作与工程项目中的结构性能提升需求; 阅读建议:建议读者结合有限元理论与优化算法知识,逐步调试Matlab代码,重点关注伴随方程的构建与p-范数的数值处理技巧,以深入掌握方法本质并实现个性化拓展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值