题目:在河两端有两排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. c17---指针

    // // main.c // 指针基本概念 #include <stdio.h> // 基本数据类型作为函数的参数是值传递, 在函数中修改形参的值不会影响到外面实参的值 void cha ...

  2. ijkplayer详解AAA

    https://www.jianshu.com/p/c5d972ab0309 https://www.android-arsenal.com/details/1/530 https://stackov ...

  3. Java-Zipkin:Zipkin 介绍

    ylbtech-Java-Zipkin:Zipkin 介绍 1.返回顶部 1. 介绍 Zipkin 是一款开源的分布式实时数据追踪系统(Distributed Tracking System),基于 ...

  4. Python 3.x 判断 dict 是否包含某个键

    Python 3.x不再支持 has_key() 函数,而被__contains__('key')所替代,会返回bool,可以用其做判断. 代码示例: >>> user = 'dad ...

  5. python 下 excel,csv 文件的读写

    python 可以用利用xlrd 库读取数据excel数据,可以用xlwt写入excel数据,用csv 操作csv文件 xlrd xlwt  python 模块 官方链接  https://pypi. ...

  6. Codeforces Round #198 (Div. 2)E题解

    E. Iahub and Permutations Iahub is so happy about inventing bubble sort graphs that he's staying all ...

  7. selenium 最大化浏览器是解决浏览器和驱动不匹配的方法如下

    那么要想selenium成功的操作chrome浏览器需要经历如下步骤: 1.下载ChromeDriver驱动包(下载地址: http://chromedriver.storage.googleapis ...

  8. Pinpoint 监控

    ####Hbase数据################ 参考: 然而没有卵用: https://blog.csdn.net/iamlihongwei/article/details/52882749? ...

  9. 通过阅读《React 进阶之路》之学习笔记

    第一章: React 通过引入虚拟DOM.状态.单向数据流等设计理念,形成以组件为核心,用组件搭建UI的开发模式.

  10. css round corner div and transition

    看stackoverflow上的圆角标签挺好看,自己动手试了下,用的属性是border-radius(即边框圆角半径,用px):加上transition effect,代码如下: <!DOCTY ...