题目描述

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. k8s pod.yml解释

    apiVersion: v1kind: Podmetadata:  name: yueying  namespace: kube-public  labels:    name: testpodssp ...

  2. Adobe PhotoShop CS6中文破解版下载

    在网上找了好多个PhotoShop破解版,但安装过程中都出现一些问题,用不了.现在找到一个比较小的PhotoShop CS6安装包,大小200M左右,下载解压,点击安装就可以使用了,安装过程十分简单. ...

  3. 2020牛客寒假算法基础集训营5 G街机争霸

    题目描述 哎,又是银首,要是你这个签到题少WA一发就金了 牛牛战队的队员打完比赛以后又到了日常甩锅的时间.他们心情悲伤,吃完晚饭以后,大家相约到一个街机厅去solo.牛牛和牛能进入了一个迷宫,这个迷宫 ...

  4. Linux高性能服务器编程:高性能服务器程序框架

    服务器有三个主要模块: (1)I/O处理单元 (2)逻辑单元 (3)存储单元 1.服务器模型 C/S模型 逻辑:服务器启动后,首先创建一个或多个监听socket,并调用bind函数将其绑定到服务器感兴 ...

  5. PAT-输入输出

    测试样例输入方式 while...EOF型(题目没有给定输入的结束条件) while(~scanf("%s",s)) {} //等价于while(scanf("%s&qu ...

  6. 2020/1/28 PHP代码审计之命令执行漏洞

    0x00 命令执行漏洞原理 应用程序有时需要调用一些执行系统命令的函数,如在PHP中,使用system.exec.shell_exec.passthru.popen.proc_popen等函数可以执行 ...

  7. js根据当前日期 求一个月前 半年前 一年前的日期

    function p(s) {        return s < 10 ? '0' + s: s;}getlastmonth() function getlastmonth() {    va ...

  8. Django2.0模型基础——(一)

    Django模型封装python操作数据库的代码,让我们可以更加方便的执行SQL语句.每个创建的app下都会有一个叫models.py的文件,在这个文件下创建的模型类映射于数据库的表名,类属性映射于数 ...

  9. UML的用例图

    1.概念理解 (1)用例图是UML多种图形语言的一种,最能体现系统结构,直观展现系统功能模块模型 (2)用例图用于描述用户与用例(角色与功能模块)之间的关联关系 (3)常用Power Designer ...

  10. sudo输入密码

    网易云音乐, 启动问题. 修改 .desktop 文件 Exec=sh /home/xyq/.music.sh # ~/.music.sh echo 密码 | sudo -S netease-clou ...