2363: 瀹岀編鏃楁墜闃熷垪
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2363: 瀹岀編鏃楁墜闃熷垪相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/limit' title='limit'>limit
can center IV 閫夋嫨 bbs csharp for include2363: 瀹岀編鏃楁墜闃熷垪
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 145 Solved: 7
[Submit][Status][Web Board]
Description
YT澶у瀹氫簬5鏈?6鏃ヤ妇琛屾牎杩愬姩浼氥€傚鏍℃湁 n 涓郴銆傜粍濮斾細瑕佹眰姣忎釜绯绘湁 m 涓繍鍔ㄥ憳鍙傚姞寮€骞曞紡锛屽苟涓旀瘡涓郴鐨?m 涓繍鍔ㄥ憳绔欐垚涓€闃熴€傛垜浠亣璁?n*m 鍚嶈繍鍔ㄥ憳绔欐垚涓€涓猲琛宮鍒楃殑闃熷垪锛岃〃绀轰负Anm锛氫笅鍥句腑鐨勬瘡涓€琛屼唬琛ㄤ竴涓郴銆?/p>
a11 a12 a13 鈥?/span> a1m
a21 a22 a23 鈥?/span> a2m
鈥?/span> 鈥?/span> 鈥?/span> 鈥?/span> 鈥?/span>
an1 an2 an3 鈥?/span> anm
鐜扮粍濮斾細瑕佹眰姣忕郴鍦?m 涓繍鍔ㄥ憳涓€夊嚭涓€鍚嶆棗鎵嬬珯鍦ㄦ湰绯荤殑鍓嶉潰锛屼负浜嗚瑙変笂鐨勭編瑙傦紝瑕佹眰鐩搁偦鐨勬棗鎵嬭韩楂樺樊璺濆敖鍙兘鐨勫皬锛屽舰鎴愪竴涓畬缇庢棗鎵嬮槦鍒椼€傛瘮濡傛垜浠粠涓婅堪闃熷垪涓€夋嫨鍑簕a12, a24, a33, 鈥?/span> , ank}浣滀负鏃楁墜闃熷垪銆傚垯杩檔涓汉鐨勮韩楂樺樊鏈€灏忕殑闃熷垪鏄畬缇庢棗鎵嬮槦鍒椼€傛瘮濡傛湁4涓郴锛屽悇绯婚€夋嫨鐨勬棗鎵嬪垎鍒负a锛宐锛?c锛?d锛?鍒?val=|a-b|+|b-c|+|c-d| 鏈€灏忕殑閫夋嫨涓哄畬缇庢棗鎵嬮槦鍒椼€備綘鑳藉府YT澶у閫夋嫨瀹岀編鏃楁墜闃熷垪鍚楋紵
Input
澶氫釜娴嬭瘯鏍蜂緥锛屾瘡涓祴璇曟牱渚嬬涓€琛屼负涓や釜鏁存暟n, m (1 <= n, m <= 1000) 锛屾帴鐫€鏄痭琛屾暣鏁版暟鍒楋紝琛ㄧず鍘熷鐨勯槦鍒楋紝鏁存暟鍊艰〃绀鸿繍鍔ㄥ憳鐨勮韩楂橈紙<=10000锛夈€?/p>
Output
瀵逛簬姣忎竴涓祴璇曟牱渚嬶紝杈撳嚭鏈€灏忕殑val鍊笺€?/p>
Sample Input
3 3 2 3 1 4 7 6 7 9 2
Sample Output
3
HINT
鏃楁墜鐨勮韩楂樻槸3, 4鍜?銆?/p>
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> using namespace std; #define MIN(aa,bb) aa<bb? aa:bb #define inf 1<<30 int n,m,cap[1010][1010]; int Min[1010][1010]; int main() { int i,j; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) { for(j=0;j<m;j++) scanf("%d",&cap[i][j]); sort(cap[i],cap[i]+m); } memset(Min,0,sizeof(Min)); for(i=1;i<n;i++) { for(j=0;j<m;j++) { Min[i][j]=inf; int temp=lower_bound(cap[i-1],cap[i-1]+m,cap[i][j])-cap[i-1]; if(temp<m) Min[i][j]=MIN(Min[i][j],Min[i-1][temp]+abs(cap[i-1][temp]-cap[i][j])); if(temp>0) Min[i][j]=MIN(Min[i][j],Min[i-1][temp-1]+abs(cap[i-1][temp-1]-cap[i][j])); } } int ans=inf; for(i=0;i<m;i++) ans=MIN(ans,Min[n-1][i]); printf("%d ",ans); } return 0; }
銆€銆€
以上是关于2363: 瀹岀編鏃楁墜闃熷垪的主要内容,如果未能解决你的问题,请参考以下文章
template might not exist or might not be accessible by any of the configured Template Resolvers 瀹岀編瑙
鏁版嵁缁撴瀯涓庣畻娉曪紙Python鐗堬級锛氱敤闃熷垪锛圦ueue锛夊鐞嗙害鐟熷か闂