隧道TunnelsMeiju
来源:互联网 发布:发条js调试工具 2.0 编辑:程序博客网 时间:2024/04/29 06:11
package work;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TunnelsMeiju {
static int N, V, H;
static int[][] S;
static int C1, R1, M1, C2, R2, M2;
//static int min_rowcost;// 一排最少花费
static int[] mincost;// 每排花费数组
static int totalcost;//
public static void main(String args[]) throws FileNotFoundException {
/* Scanner sc=new Scanner(System.in); */
Scanner sc = new Scanner(new File("src/tunnels.txt"));
int T = sc.nextInt();
for (int t = 0; t < T; t++) {
N = sc.nextInt();
H = sc.nextInt();
V = sc.nextInt();
S = new int[V][H];
mincost = new int[V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < H; j++) {
S[i][j] = sc.nextInt();
}
}
C1 = sc.nextInt();
R1 = sc.nextInt();
M1 = sc.nextInt();
C2 = sc.nextInt();
R2 = sc.nextInt();
M2 = sc.nextInt();
for (int v = 0; v < V; v++) {
mincost[v] = find(v);
}
totalcost = 0xfffffff;
for (int i = 0; i <= V-1-(N-1)*2; i++) {
dfs(1,i,mincost[i]);
}
System.out.println("Case#"+" "+(t+1));
System.out.println(totalcost);
}
}
private static void dfs(int step, int last, int cost) {
if(step==N){
if(totalcost>cost)
totalcost=cost;
return;
}
for (int next = last+2; next <V-1-(N-1-step)*2 ; next++) {
cost =cost +mincost[next]+(M1*M1+M2*M2)*(next-last);
dfs(step+1,next,cost );
}
}
private static int find(int v) {
int min_rowcost = 0xfffffff;
for (int i = 0; i <= H; i++) {
int sum = 0;
for (int j = 0; j < i; j++){
sum += S[v][j] * C1;}
for (int j = i; j < H; j++)
{sum += S[v][j] * C2;}
if (H - i > i)
sum += (H - 2 * i - 1) * R2;
if (H - i < i)
sum += (i - (H - i) - 1) * R1;
if (sum < min_rowcost)
min_rowcost = sum;
}
return min_rowcost;
}
}
、、input
3
1 3 1
42 3 99
4 19 3
4 1 5
1 5 1
1 4 1 3 11
7 2 3
2 6 4
3 5 6
50 50 50 50 50
50 50 50 50 50
50 50 50 50 50
50 50 50 50 50
50 50 50 50 50
50 50 50 50 50
10 10 10
20 10 5
、、output
Case# 1
576
Case# 2
57
Case# 3
8120
- 隧道TunnelsMeiju
- 隧道20051024
- Http隧道
- 时空隧道
- SSH隧道
- 隧道技术
- SSH 隧道
- SSH隧道
- 隧道协议
- ssh隧道
- SSH隧道
- 隧道技术
- GRE隧道
- SSH隧道
- HTTPS隧道
- SSH隧道
- 隧道技术
- ssh隧道
- [杂项]测试
- 【WPF】C#用POST请求参数含中文,服务器解析得到乱码问题
- Python初学,web.py的Hello World
- Java并发编程的艺术(八)——闭锁、同步屏障、信号量详解
- Android RecyclerView滚动定位到item,并使其置顶
- 隧道TunnelsMeiju
- 对话框类的数据交换
- JavaScript双击、单击事件并存的一种解决思路
- 枚举类型绑定下拉列表
- 【AI每日播报】Jeff Dean回顾 Google Brain 2016:机器学习取得重大进展
- 线段树及Lazy-Tag
- pat 1104
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错
- centos6.5 安装git