题目描述

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. 《C Primer Plus》- 第二章 C语言概述

    本笔记写于2020年1月27日. 本系列文章参考的是<C Primer Plus>(第六版),其中里面会有笔者自己的相关补充. 以下示例均运行于macOS Catalina 10.15.2 ...

  2. 小程序调用wx.chooseLocation接口的时候无法获取权限(ios)

    ios手机小程序调用wx.chooseLocation接口的时候,获取权限的时候报authorize:fail:require permission desc这样子的错误,这是由于苹果的安全机制导致需 ...

  3. Java 14 令人期待的 5 大新特性,打包工具终于要来了

    随着新的 Java 发布生命周期的到来,新版本预计将于 2020 年 3 月发布,本文将对其中的 5 个主要特性作些概述. Java 13刚刚发布给开发人员使用不久,最新版本的JDK于2019年9月发 ...

  4. STM32F407的Modbus做为主站与从站通讯

    在调试STM32F407的串口Modbus通讯之前,也使用过Modbus通讯,只不过都是在PLC或则昆仑通态的触摸屏上使用直接调用现成的库里面的模块,驱动就可以,相对于STM32来,使用PLC库里面的 ...

  5. 使用linux服务器安装wordpress博客详细教程

    前言 最近读了<软技能:代码之外的生存指南>,这本书给了我很大的启示.之前虽然知道作为一个程序员,应该拥有自己的博客,以便于提升自己的知名度,但是并没有了解的过于详细.这本书描写博客的作用 ...

  6. h5-圆角的使用-案例安卓机器人

    1.圆角的使用 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  7. js中将json字符串转换成json对象

    在我们使用js请求后台控制器传回的结果result值的时候,经常会出现返回结果值为json字符串的情况,字符串无法在js中直接使用 返回样式栗子: 这是一个json字符串:result = " ...

  8. 手机H5,用Jquery使图片自动填满两栏式排版

    遇上这样的排版,手机的解象度都不同,假如只用CSS3根本就做不出这样的排版:因此要用Jquery. 1. HTML <div class="postImgCenterCrop" ...

  9. Springboot项目绑定域名,使用Nginx配置Https

    一.https 简介     HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HT ...

  10. PAT Advanced 1052 Linked List Sorting (25) [链表]

    题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...