一简单的状压题 比赛时跑偏了 ,脑子最近乱的跟浆糊似得呢。。

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 using namespace std;
 8 int dp[15][5010],o[15][5010];
 9 int w[15][15],ee[15][15],s[15];
10 int main()
11 {
12     int i,j,n,t,e;
13     cin>>t;
14     while(t--)
15     {
16         memset(dp,0,sizeof(dp));
17         memset(o,0,sizeof(o));
18         cin>>n;
19         for(i = 1; i <= n ;i++)
20             for(j = 1; j <= n ; j++)
21             cin>>w[i][j];
22         for(i = 1; i <= n ; i++)
23             for(j = 1; j <= n ;j++)
24             cin>>ee[i][j];
25         for(i = 1; i <= n ;i++)
26             cin>>s[i];
27         if(n==1)
28         {
29             cout<<"0\n";
30             continue;
31         }
32         for(i = 1 ; i < n ;i++)
33         {
34             if(s[1]>s[i+1])
35             {
36                 dp[1][1<<(i-1)] = ee[1][i+1];
37             }
38             else
39             dp[1][1<<(i-1)] = 0;
40             o[1][1<<(i-1)] = 1;
41         }
42         for(i = 2; i < n ;i++)
43         {
44             for(j = 0 ; j < (1<<(n-1)) ; j++)
45             {
46                 int ts=s[1];
47                 if(!o[i-1][j]) continue;
48                 for(e = 1 ; e < n ; e++)
49                 {
50                     if(j&(1<<(e-1)))
51                     {
52                         ts+=w[1][e+1];
53                     }
54                 }
55                 for(e = 1; e < n ; e++)
56                 {
57                     if((j&(1<<(e-1)))==0)
58                     {
59                         if(ts>s[e+1])
60                         dp[i][j+(1<<(e-1))] = max(dp[i][j+(1<<(e-1))],dp[i-1][j]+ee[1][e+1]);
61                         else
62                         dp[i][j+(1<<(e-1))] = max(dp[i][j+(1<<(e-1))],dp[i-1][j]);
63                         o[i][j+(1<<(e-1))] = 1;
64                     }
65                 }
66             }
67         }
68         cout<<dp[n-1][(1<<(n-1))-1]<<endl;
69     }
70     return 0;
71 }
72
73
74
75
76 /**************************************
77     Problem id    : SDUT OJ 1283
78     User name    : shang
79     Result        : Accepted
80     Take Memory    : 1060K
81     Take Time    : 0MS
82     Submit Time    : 2014-02-14 23:02:39
83 **************************************/

View Code

转载于:https://www.cnblogs.com/shangyu/p/3550663.html

sdut1283Five in a Row, Again相关推荐

  1. ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'name' at row 1

    ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'name' at row 1 数据库字符集问题,查 ...

  2. eureka需要替换吗_iOS第三方库Eureka实现定制动画详解(二):万变不离其宗-Row组件...

    Eureka的核心就是Row,所以我们得重点聊聊它.Row是什么?其实上面已经说过了,不过这只是干巴巴的概念,下面本猫用一个实际的例子带大家性感,哦,不-是感性的认识一下到底什么是Row 新建一个iO ...

  3. pandas使用max函数和min函数计算dataframe日期(时间)数据列中最大日期和最小日期对应的数据行(maximum and minimum date or time row)

    pandas使用max函数和min函数计算dataframe日期(时间)数据列中最大日期和最小日期对应的数据行(maximum and minimum date or time row in data ...

  4. numpy使用[]语法索引二维numpy数组中指定行列位置的数值内容(access value at certain row and column in numpy array)

    numpy使用[]语法索引二维numpy数组中指定行列位置的数值内容(access value at certain row and column in numpy array) 目录

  5. numpy使用[]语法索引二维numpy数组中指定指定行之后所有数据行的数值内容(accessing rows in numpy array after specifc row)

    numpy使用[]语法索引二维numpy数组中指定指定行之后所有数据行的数值内容(accessing rows in numpy array after specifc row) 目录

  6. pandas索引复合索引dataframe数据、索引其中一个水平(level)的所特定数据行、指定数据行(index a row of a level)、使用元组tuple表达复合索引的指定行

    pandas索引复合索引dataframe数据.索引其中一个水平(level)的所特定数据行.指定数据行(index a row of a level).使用元组tuple表达复合索引的指定行 目录

  7. pandas使用idxmax函数获取dataframe每个数据行中最大值对应的列名称(column label of max value in each row in dataframe)

    pandas使用idxmax函数获取dataframe每个数据行中最大值对应的列名称(column label of max value in each row in dataframe) 目录

  8. numpy使用[]语法索引二维numpy数组中指定数据行的数值内容(accessing the specific row in numpy array)

    numpy使用[]语法索引二维numpy数组中指定数据行的数值内容(accessing the specific row in numpy array) 目录 numpy使用[]语法索引二维numpy ...

  9. pandas使用itertuples函数迭代dataframe中的数据行并自定义修改行中的数值(update row while iterating over the rows)

    pandas使用itertuples函数迭代dataframe中的数据行并自定义修改行中的数值(update row while iterating over the rows in datafram ...

最新文章

  1. LeetCode刷题-6
  2. 使用Leangoo共享脑图/思维导图做多级需求管理
  3. Whois 机器人及其它相关信息
  4. .NET Core 返回结果统一封装
  5. 服务器 风扇测试软件,图解服务器风扇安装的正确方法
  6. java jlabe_[求助]JPanel上怎么移除JLabe。l
  7. 如何解决无法显示隐藏文件文件夹
  8. mfc listbox删除多行
  9. 安装mongodb时为什么一直卡着不动
  10. 性格决定命运--从流浪汉到亿万富翁[taylor]
  11. 三角形的外心 内心 重心 垂心 九点圆心与各圆半径的算法
  12. android lrc歌词解析,Android解析lrc里的歌词
  13. Java、JSP大阳电动车销售系统的设计与实现
  14. MIT JOS lab2内存管理实验记录
  15. 【总结】初创公司用AWS搭建高扩展性架构
  16. 1080MOOC期中成绩
  17. 弊润落幅跨越60%的无5野婆司
  18. 走马观花之bug预防
  19. Aegisub设置字体透明度
  20. ZigBee技术简介,以及ZigBee的未来展望

热门文章

  1. 机器学习实战 | 数据探索
  2. 重采样和重分类的区别
  3. android倒计时动画特效,Android仿活动时分秒倒计时效果
  4. php 判断点在多边形内,PHP判断点是否在多边形区域内外
  5. 查看本地oracle密码是多少钱,Oracle 本地验证和密码文件
  6. 基于STM32-HAL库的直流电机控制
  7. python和c#交互_python与C#的互相调用
  8. lc 115. Distinct Subsequences
  9. 浏览器截图插件什么的弱爆了
  10. C# 循环语句 for