栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2059 The Twin Towers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2059 The Twin Towers

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#define max( a, b ) ((a)>(b)?(a):(b))int f[ 1001 ];int t[ 1001 ];int h[ 101 ];int main(){    int n,s;    while ( scanf("%d",&n) != EOF && n != -1 ) {        s = 0;        for ( int i = 1 ; i <= n ; ++ i ) { scanf("%d",&h[ i ]); s += h[ i ];        }        s /= 2;        memset( f, 0, sizeof( f ) );        memset( t, 0, sizeof( t ) );        for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 0 ; j <= s ; ++ j )     if ( t[ j ] ) {         f[ j+h[ i ] ] = max( t[ j ]+h[ i ], f[ j+h[ i ] ] );         f[ abs(h[ i ]-j) ] = max( max( t[ j ], t[ j ]+h[ i ]-j ), f[ abs(h[ i ]-j) ] );     } f[ h[ i ] ] = max( h[ i ], f[ h[ i ] ] ); for ( int j = 0 ; j <= s ; ++ j )     f[ j ] = max( f[ j ], t[ j ] ); for ( int j = 0 ; j <= s ; ++ j )      t[ j ] = f[ j ];        }        if ( f[ 0 ] ) printf("%dn",f[ 0 ]);        else printf("Sorryn");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375909.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号