题目:bzoj5248 https://www.lydsy.com/JudgeOnline/problem.php?id=5248

   洛谷P4363 https://www.luogu.org/problemnew/show/P4363

终于A了(虽然得开O2才能过)!

其实就是暴搜,用一个 n+1 进制数表示状态,进行最优策略转移即可;

注意 cnt[] 如果开成全局变量就不能每次翻译那个 n+1 进制数,否则会影响其它层的搜索;

(还有一种神奇的状态压缩是有几个用了 k 个1的列,就在第 k 个0后面加几个1……)

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>mp;
map<ll,bool>vis;
int n,m,s[][][],inf=1e9,cnt[];
ll pw(int a,int b)
{
ll ret=;
while(b){if(b&)ret*=a;a*=a;b>>=;}
return ret;
}
ll dfs(ll x,bool f)
{
if(vis[x])return mp[x];
vis[x]=;mp[x]=-inf;ll tx=x;
// for(int i=m;i;i--)cnt[i]=tx%(n+1),tx/=(n+1);
if(cnt[m]==n)return mp[x]=;
for(int i=;i<=m;i++)
{
if(cnt[i]==n||(i>&&cnt[i-]<=cnt[i]))continue;
cnt[i]++;
ll y=x+pw(n+,m-i);
mp[x]=max(mp[x],s[f][cnt[i]][i]-dfs(y,!f));
cnt[i]--;
}
return mp[x];
}
int main()
{
scanf("%d%d",&n,&m);
for(int k=;k<=;k++)
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&s[k][i][j]);
printf("%lld",dfs(,));
}

最新文章

  1. 大熊君JavaScript插件化开发------(实战篇之DXJ UI ------ ItemSelector)
  2. 微信网页授权snsapi_base、snsapi_userinfo的问题
  3. matlab linux 安装
  4. iOS resign code with App Store profile and post to AppStore
  5. [转]Flash Socket通信的安全策略
  6. S2--《优化MySchool数据库设计》总结
  7. 错误记录--The import XXX cannot be resolved
  8. Ubuntu下安装可视化SVN客户端Rabbitvcs
  9. 4月13日学习笔记——jQuery工具函数
  10. .Net IE10 _doPostBack 未定义
  11. 开始学习HTML5
  12. MSChart实例
  13. 从花式swap引出的pointer aliasing问题
  14. EF异常探究(An entity object cannot be referenced by multiple instances of IEntityChangeTracker.)
  15. clique
  16. Generator和Async
  17. npm WARN enoent ENOENT: no such file or directory, open &#39;C:\Users\package.json&#39;
  18. 怎样下载youtube的字幕
  19. python如何去掉字符串‘\xa0’
  20. 获取地图文档(*.mxd)中比例尺问题

热门文章

  1. devstack脚本安装Openstack总结(转载)
  2. dfs树上的边
  3. Toad Oracle 本地/远程数据库导入/导出 数据库备份
  4. Codeforces936C. Lock Puzzle
  5. P1546||2627 最短网络 Agri-Net 洛谷||codevs
  6. maven生命周期和依赖的范围
  7. 基于51单片机的CAN通讯协议C语言程序
  8. 淘宝API学习之道:淘宝TOP之API接口接入教程
  9. Codeforces466C Number of Ways
  10. ZrcListView