题目:在河两端有两排server,如今要把河两边同样的品牌型号的机器连起来。每一个电脑有个值,

每一个机器仅仅能与还有一台机器链接。而且不同的链接不交叉,如今要求链接的电脑总之最大。

分析:dp,最大公共子序列,字符串。还要加一个字符串处理。

说明:(2011-09-19 11:08)。

#include <stdio.h>
#include <stdlib.h>
#include <string.h> #define max( a, b ) ((a)>(b)?(a):(b)) char LeftOS[ 1001 ][ 12 ];
char RightOS[ 1001 ][ 12 ];
int LeftID[ 1001 ];
int LeftV[ 1001 ];
int RightID[ 1001 ];
int RightV[ 1001 ];
char OSList[ 1001 ][ 12 ];
int Match[ 1001 ][ 1001 ];
int Count[ 1001 ][ 1001 ];
int Number = 0; int ID( char * Data )
{
for ( int i = 0 ; i < Number ; ++ i )
if ( !strcmp( OSList[ i ], Data ) )
return i;
strcpy( OSList[ Number ], Data );
return Number ++;
} int main()
{
int t,n,m;
char City[ 12 ];
while ( ~scanf("%d",&t) )
while ( t -- ) {
scanf("%d",&n);
for ( int i = 1 ; i <= n ; ++ i )
scanf("%s %s %d",City,LeftOS[ i ],&LeftV[ i ]);
scanf("%d",&m);
for ( int i = 1 ; i <= m ; ++ i )
scanf("%s %s %d",City,RightOS[ i ],&RightV[ i ]); Number = 0;
for ( int i = 1 ; i <= n ; ++ i )
LeftID[ i ] = ID( LeftOS[ i ] );
for ( int i = 1 ; i <= m ; ++ i )
RightID[ i ] = ID( RightOS[ i ] ); memset( Match, 0, sizeof( Match ) );
memset( Count, 0, sizeof( Count ) ); for ( int i = 1 ; i <= n ; ++ i )
for ( int j = 1 ; j <= m ; ++ j ) {
if ( Match[ i ][ j ] < Match[ i-1 ][ j ] ) {
Match[ i ][ j ] = Match[ i-1 ][ j ];
Count[ i ][ j ] = Count[ i-1 ][ j ];
}
if ( Match[ i ][ j ] < Match[ i ][ j-1 ] ) {
Match[ i ][ j ] = Match[ i ][ j-1 ];
Count[ i ][ j ] = Count[ i ][ j-1 ];
}
if ( LeftID[ i ] == RightID[ j ] && Match[ i ][ j ] < Match[ i-1 ][ j-1 ] + LeftV[ i ] + RightV[ j ] ) {
Match[ i ][ j ] = Match[ i-1 ][ j-1 ] + LeftV[ i ] + RightV[ j ];
Count[ i ][ j ] = Count[ i-1 ][ j-1 ] + 1;
}
} printf("%d %d\n",Match[ n ][ m ],Count[ n ][ m ]);
}
return 0;
}

zoj 3034 - The Bridges of Kolsberg的更多相关文章

  1. ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang

    Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country ...

  2. 【求无向图的桥,有重边】ZOJ - 2588 Burning Bridges

    模板题——求割点与桥 题意,要使一个无向图不连通,输出必定要删掉的边的数量及其编号.求桥的裸题,可拿来练手. 套模板的时候注意本题两节点之间可能有多条边,而模板是不判重边的,所以直接套模板的话,会将重 ...

  3. zoj 2588 Burning Bridges【双连通分量求桥输出桥的编号】

    Burning Bridges Time Limit: 5 Seconds      Memory Limit: 32768 KB Ferry Kingdom is a nice little cou ...

  4. zoj——2588 Burning Bridges

    Burning Bridges Time Limit: 5 Seconds      Memory Limit: 32768 KB Ferry Kingdom is a nice little cou ...

  5. ZOJ 2588 Burning Bridges(无向连通图求割边)

    题目地址:ZOJ 2588 由于数组开小了而TLE了..这题就是一个求无向连通图最小割边.仅仅要推断dfn[u]是否<low[v],由于low指的当前所能回到的祖先的最小标号,增加low[v]大 ...

  6. ZOJ 2588 Burning Bridges(求桥的数量,邻接表)

    题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2588 Burning Bridges Time Limit: 5 ...

  7. 2014 Super Training #2 F The Bridges of Kolsberg --DP

    原题:UVA 1172  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. ZOJ 2588 Burning Bridges (tarjan求割边)

    题目链接 题意 : N个点M条边,允许有重边,让你求出割边的数目以及每条割边的编号(编号是输入顺序从1到M). 思路 :tarjan求割边,对于除重边以为中生成树的边(u,v),若满足dfn[u] & ...

  9. zoj 2588 Burning Bridges

    题目描述:Ferry王国是一个漂亮的岛国,一共有N个岛国.M座桥,通过这些桥可以从每个小岛都能到达任何一个小岛.很不幸的是,最近Ferry王国被Jordan征服了.Jordan决定烧毁所有的桥.这是个 ...

随机推荐

  1. wpf Listbox 设置ItemContainerStyle后,ItemTemplateSelector不能触发

    解决方案: 将Listbox 的ItemTemplateSelector 改为 ItemContainerStyle中ContentPresenter ContentTemplateSelector ...

  2. 什么是 SHTML

    什么是 SHTML 使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为“服务器端嵌入”或者叫“服务器端包含”,是一种类 ...

  3. 学习 java netty (一) -- java nio

    前言:近期在研究java netty这个网络框架,第一篇先介绍java的nio. java nio在jdk1.4引入,事实上也算比較早的了.主要引入非堵塞io和io多路复用.内部基于reactor模式 ...

  4. Vue常用插件总结

    Vue-router ----- 路由插件 Vue-loader-----webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件   Vue-resource-----提供了使用 ...

  5. Python+unittest 接口自动化测试

    1.封装get.post#!/usr/bin/env python3# -*- coding: utf-8 -*- __author__ = 'hualai yu' import requests c ...

  6. Meson使用

    安装 Meson是基于python3实现,至少需要python3.5才能运行,默认采用ninja作为后端.在Ubuntu下最简单的是通过pip3安装 $ sudo apt-get install py ...

  7. 爱,死亡和机器人 第十四集 齐马蓝 中文字幕(Python处理utf8文件获取想要的内容)

    处理代码 file = "a.srt" fi = open(file, mode='r') a = fi.readline() i = 1 while len(str(a)) != ...

  8. 【SQL】SELECT 语句

    1.1 SELECT基本语法: Select * |{[distinct]colum|expression [alias],…} from table; 1.2 查询当前用户所有在用的表及视图: HR ...

  9. 使用QT的一些小Tipster

    1.在使用Qt Creator编程时,难免会用到将float类型转换为QString类型的方法:原文 1.1. 将QString类型转化为float类型,很简单 QString data;       ...

  10. PhotoZoom官方这举动,大写服!

    上上周,PhotoZoom Classic7首次特惠活动大家都知道哈~~ 厂商福利限量30套,仅售99RMB,活动一经上线,半天时间一售而光,这说明不是大家不需要这个智能小软件啊,而是,可能,大概,也 ...