题目描述

JSZKC is going to spend his vacation! 
His vacation has N days. Each day, he can choose a T-shirt to wear. Obviously, he doesn’t want to wear a singer color T-shirt since others will consider he has worn one T-shirt all the time. 
To avoid this problem, he has M different T-shirt with different color. If he wears A color T-shirt this day and B color T-shirt the next day, then he will get the pleasure of f[A][B].(notice: He is able to wear one T-shirt in two continuous days but may get a low pleasure) 
Please calculate the max pleasure he can get. 

输入

The input file contains several test cases, each of them as described below.

  • The first line of the input contains two integers N,M (2 ≤ N≤ 100000, 1 ≤ M≤ 100), giving the length of vacation and the T-shirts that JSZKC has.
  • The next follows M lines with each line M integers. The jth integer in the ith line means f[i][j](1<=f[i][j]<=1000000).

There are no more than 10 test cases. 

输出

One line per case, an integer indicates the answer 

样例输入

3 2
0 1
1 0
4 3
1 2 3
1 2 3
1 2 3

样例输出

2
9
题解
看了大佬的代码,迷迷糊糊的
题意很好理解
这里用了倍增的思想
倍增思想之前接触过一道题
f[i][j][k]表示走2^i次,从j->k的最大价值,状态压缩?
然后用了二进制按位与
就是二进制位上都为1的话就说明走了这个,可以递推
n分解成x1*2^p1+x2*2^p2+x3*2^p3.....xn*2^pn
就看xi是不是为1
最后 每一步只与上一步有关 就可以0和1表示
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
ll s[][maxn][maxn];//s[a][b][c] b->c 2^a days
ll ans[][maxn][maxn];
int m,n;
int main(){
int i,j,l,k;
while(cin>>n>>m){
memset(s,,sizeof(s));
memset(ans,,sizeof(ans));
for(i=;i<=m;i++){
for(j=;j<=m;j++){
cin>>s[][i][j];
}
}
for(i=;i<=;i++){
for(j=;j<=m;j++){
for(l=;l<=m;l++){
for(k=;k<=m;k++){
s[i][j][l]=max(s[i][j][l],s[i-][j][k]+s[i-][k][l]);
}
}
}
}
n--;
int temp=;
for(i=;i<;i++){
if(n&(<<i)){
for(j=;j<=m;j++){
for(k=;k<=m;k++){
for(l=;l<=m;l++){
ans[temp][j][k]=max(ans[temp][j][k],ans[-temp][j][l]+s[i][l][k]);
}
}
}
temp=-temp;
}
}
temp=-temp;
ll maxx=;
for(i=;i<=m;i++){
for(j=;j<=m;j++){
maxx=max(ans[temp][i][j],maxx);
}
}
cout<<maxx<<endl;
}
return ;
}

这个是状态压缩DP:https://www.cnblogs.com/ibilllee/p/7651971.html

												

T-shirt的更多相关文章

  1. 新概念英语(1-11)Is this your shirt ?

    Is this your shirt?Whose shirt is white? A:Whose shirt is that? Is this your shirt, Dave? Dave:No si ...

  2. Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口”

    Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口” Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directo ...

  3. SELECT s.* FROM person p INNER JOIN shirt s ON s.owner = p.id WHERE p.name LIKE 'Lilliana%' AND s.color <> 'white';

    SELECT s.* FROM person p INNER JOIN shirt sON s.owner = p.idWHERE p.name LIKE 'Lilliana%'AND s.color ...

  4. [Eclipse插件] Eclipse设置Tab键为空格(ctrl+shirt+f格式化生效)!

    自定义format格式,用空格替换Tab键,ctrl+shit+f格式化后生效: 设置Eclipse中按Tab键为4个空格,这里标记下! Window-->Preferences-->Ja ...

  5. javascript arguments(转)

    什么是arguments arguments 是是JavaScript里的一个内置对象,它很古怪,也经常被人所忽视,但实际上是很重要的.所有主要的js函数库都利用了arguments对象.所以agru ...

  6. Linux.NET实战手记—自己动手改泥鳅(下)

    在上回合中,我们不痛不痒的把小泥鳅的数据库从只能供在Windows下运行的Access数据库改为支持跨平台的MYSQL数据库,毫无营养的修改,本回合中,我们将把我们修改后得来的项目往Linux中部署. ...

  7. MySQL基础

    数据库操作 ---终端使用数据库 mysql -u root -p 之后回车键 输入密码 ---显示所有数据库: show databases; ---默认数据库: mysql - 用户权限相关数据 ...

  8. Swift3.0P1 语法指南——构造器

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  9. Python之美--Decorator深入详解

    转自:http://www.cnblogs.com/SeasonLee/archive/2010/04/24/1719444.html 一些往事 在正式进入Decorator话题之前,请允许我讲一个小 ...

  10. Normalization

    In creating a database, normalization is the process of organizing it into tables in such a way that ...

随机推荐

  1. quartz 集成到Spring中

    记录一下,防止忘记. 需要的jar包,quartz-2.2.3.jar,commons-collection-3.1.jar,spring-context-support-4.3.4.RELEASE. ...

  2. contos7 共享文件夹开机自动挂载

    网上很多文章都说改文件/etc/fstab 我试了很多次都不行 然后看到另一个方法 在/etc/rc.d/rc.local 增加挂在脚本这个时候要注意执行权限问题 我是这样做的 sudo mount ...

  3. 设计模式讲解5:FlyWeight模式源码

    声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 FlyWeight模式即享元模式.很多文本编辑器中都使用了FlyWeight模式.FlyWeight单词含 ...

  4. pycharm调试、设置汇总

    目录: 1.pycharm中不能run 2.pycharm基本调试操作 3.pycharm使用技巧 4.pycharm Error running draft: Cannot run program ...

  5. 内存管理之栈stack

    1.什么是栈   栈是一种数据结构,C语言中使用栈来保存局部变量.栈是被发明出来管理内存的.2.栈管理内存的特点(小内存.自动化)   先进后出  FILO   first in last out   ...

  6. 计算机网络(6): http cookie

    Cookie作用: 1)帮助管理用户会话信息(用户需要记录的信息:登陆状态等) 2)跟踪浏览器的行为 3)用户自定义设置 实现方式: 当用户浏览带有Cookie的网站时,网站自动为其生成一个唯一的标志 ...

  7. ubuntu搭建web服务器

    https://www.linuxidc.com/Linux/2015-11/125477.htm 到“sudo apt-get install libapache2-mod-php5”出现1错误.

  8. 吴裕雄--天生自然 PHP开发学习:表单 - 验证邮件和URL

    $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $ ...

  9. 01 语言基础+高级:1-3 常用API第一部分_day07【Scanner类、Random类、ArrayList类】

    day07[Scanner类.Random类.ArrayList类] Scanner类Random类ArrayList类 教学目标 能够明确API的使用步骤能够使用Scanner类获得键盘录入数据能够 ...

  10. object detection模型转换成TensorFlow Lite,在Android应用

    环境 tensorflow = 1.12.0 bazel = 0.18.1 ubuntu = 16.04 python = 3.6.2 安装 bazel (0.18.1) 如果tensorflow是1 ...