Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1559232
  • 博文数量: 327
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 3556
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-05 21:28
个人简介

东黑布衣,流浪幽燕。 真诚善良,值得信赖。

文章分类

全部博文(327)

我的朋友

分类: BSD

2016-09-28 20:18:43



点击(此处)折叠或打开

  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #define MAX_ROW 4
  4. #define MAX_COL 5
  5. #define INT_MAX (int)((unsigned int)~0 >> 1)

  6. int lin_mm[MAX_ROW];
  7. int N,H,V;

  8. int mark[MAX_ROW];
  9. int last_pos;
  10. int last[5];
  11. int d_sum;
  12. int sum;
  13. int m1,m2;
  14. int result;
  15. void tunnel_select(int tunnel)
  16. {
  17.    int i;
  18.    if(tunnel==N+1)
  19.    {
  20.       last_pos=-1;
  21.       d_sum=0;
  22.       sum=0;
  23.       for(i=0;i<MAX_ROW;i++)
  24.       {
  25.          if(mark[i]==1 && last_pos==-1)
  26.          {
  27.             last_pos=i;
  28.             sum+=lin_mm[i];
  29.          }
  30.          else if(mark[i]==1)
  31.          {
  32.             d_sum+=(i-last_pos);
  33.             last_pos=i;
  34.             sum+=lin_mm[i];
  35.          }
  36.          
  37.       }
  38.       sum+=(m1*m1+m2*m2)*d_sum;
  39.       if(result>sum)
  40.          result=sum;
  41.       return;
  42.    }

  43.    for(i=0;i<V;i++)
  44.    {
  45.       if(tunnel==1 && mark[i]==0)
  46.       {
  47.          mark[i]=1;
  48.          last[tunnel-1]=i;
  49.          tunnel_select(tunnel+1);
  50.          mark[i]=0;
  51.       }
  52.       else if(mark[i]==0 && i-last[tunnel-2] >1)
  53.       {
  54.          mark[i]=1;
  55.          last[tunnel-1]=i;
  56.          tunnel_select(tunnel+1);
  57.          mark[i]=0;
  58.       }
  59.       else
  60.          continue;
  61.    }
  62.    return;
  63. }
  64. int _tmain(int argc, _TCHAR* argv[])
  65. {
  66.     int S[MAX_ROW][MAX_COL];
  67.     int tmp;
  68.     int ind;
  69.     int T;
  70.     int test_case;
  71.     int i,j;
  72.     int v,h;
  73.     int c1,r1;
  74.     int c2,r2;

  75.     freopen("0928adv_tmp.txt", "r", stdin);
  76.     freopen("0928adv_out.txt", "w", stdout);

  77.     setbuf(stdout, NULL);
  78.     scanf("%d", &T);
  79.     for(test_case = 1; test_case <= T; ++test_case)
  80.     {
  81.         result=INT_MAX;
  82.         scanf("%d %d %d", &N,&H,&V);
  83.         for(v=0;v<V;v++)
  84.         {
  85.            for(h=0;h<H;h++)
  86.             scanf("%d ",&S[v][h]);
  87.            lin_mm[v]=INT_MAX;
  88.         }
  89.         scanf("%d %d %d",&c1,&r1,&m1);
  90.         scanf("%d %d %d",&c2,&r2,&m2);
  91.         for(v=0;v<V;v++)
  92.         {
  93.            for(h=0;h<H;h++)
  94.            {
  95.               i=h;
  96.               tmp=0;
  97.               for(j=0;j<i;j++)
  98.               {
  99.                  tmp+=S[v][j]*c1;
  100.               }

  101.               for(j=H-1;j>=i;j--)
  102.               {
  103.                  tmp+=S[v][j]*c2;
  104.               }

  105.               if((H-2*i) > 1)
  106.                   tmp+=(H-2*i - 1)*r2;
  107.               else if((2*i-H)>1)
  108.                   tmp+=(2*i - H - 1)*r1;
  109.               if(lin_mm[v]>tmp)
  110.               {
  111.                  ind = j;
  112.                  lin_mm[v] = tmp;
  113.               }
  114.            }
  115.         }
  116.         tunnel_select(1);
  117.         printf("#%d %d\n",test_case,result);
  118.     }
  119.     return 0;
  120. }



4
1 3 1
42 3 99
4 19 3
4 1 5
1 5 1
1 4 1 3 11
7 2 3
2 6 4
2 5 4
1 4 1 3 11
13 5 1 4 11
1 2 3 4 5
99 2 47 3 31
7 2 3
2 6 5
1 4 1
1 2 3 4
7 3 3
2 9 4


1 4 1 3 11
13 5 1 4 11
1 2 3 4 5
99 2 47 3 31

min = 57, ind=1
min = 92, ind=0
min = 45, ind=2
min = 388, ind=0










阅读(1358) | 评论(1) | 转发(0) |
0

上一篇:球拍底板的种类和选择

下一篇:Que and Stack

给主人留下些什么吧!~~

zhln2016-10-21 11:54:30

这是一个不完全版,只是第一步。