题目:在河两端有两排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. 2016.04.07,英语,《Vocabulary Builder》Unit 11

    cant, from the Latin verbs canere and cantare, meaning 'sing'. by way of French, add an h to the roo ...

  2. POJ3204 Ikki's Story - Road Reconstruction 网络流图的关键割边

    题目大意:一个有源有汇的城市,问最少增加城市中的多少道路可以增加源到汇上各个路径上可容纳的总车流量增加. 网络流关键割边集合指如果该边的容量增加,整个网络流图中的任意从原点到汇点的路径的流量便可增加. ...

  3. Linux之convert命令【转】

    本文转载自:http://zlb1986.iteye.com/blog/778054 转载: 强大的convert命令 convert命令可以用来转换图像的格式,支持JPG, BMP, PCX, GI ...

  4. Spark新愿景:让深度学习变得更加易于使用——见https://github.com/yahoo/TensorFlowOnSpark

    Spark新愿景:让深度学习变得更加易于使用   转自:https://www.jianshu.com/p/07e8200b7cea 前言 Spark成功的实现了当年的承诺,让数据处理变得更容易,现在 ...

  5. 【Codeforces 105D】 Bag of mice

    [题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...

  6. 不用任何插件,实现一个tab栏切换

    //使用jquery中获取当前索引的方法.显示隐藏 <script> $(".tab_list li").on('click', function () { $(thi ...

  7. logging (日志) 模块

    本文源自景女神 函数式简单配置 import logging logging.debug('debug message') logging.info('info message') logging.w ...

  8. redis启动加载过程、数据持久化

    背景 公司一年的部分业务数据放在redis服务器上,但数据量比较大,单纯的string类型数据一年就将近32G,而且是经过压缩后的. 所以我在想能否通过获取string数据的时间改为保存list数据类 ...

  9. 【SQL】分析函数功能-排序

    1:排名,不考虑并列问题 row_number() 2:排名,有并列,并列后的排名不连续 rank() 3:排名,有并列,并列后的排名连续 dense_rank() 测试: SQL> creat ...

  10. sphinx with discuz

    安装sphinx: sudo apt-get install sphinxsearch 配置: source discuz { type = mysql sql_host = xx.xx.xx.xx ...