T-shirt
题目描述
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 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.
输出
样例输入
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-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 ...
- Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口”
Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口” Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directo ...
- 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 ...
- [Eclipse插件] Eclipse设置Tab键为空格(ctrl+shirt+f格式化生效)!
自定义format格式,用空格替换Tab键,ctrl+shit+f格式化后生效: 设置Eclipse中按Tab键为4个空格,这里标记下! Window-->Preferences-->Ja ...
- javascript arguments(转)
什么是arguments arguments 是是JavaScript里的一个内置对象,它很古怪,也经常被人所忽视,但实际上是很重要的.所有主要的js函数库都利用了arguments对象.所以agru ...
- Linux.NET实战手记—自己动手改泥鳅(下)
在上回合中,我们不痛不痒的把小泥鳅的数据库从只能供在Windows下运行的Access数据库改为支持跨平台的MYSQL数据库,毫无营养的修改,本回合中,我们将把我们修改后得来的项目往Linux中部署. ...
- MySQL基础
数据库操作 ---终端使用数据库 mysql -u root -p 之后回车键 输入密码 ---显示所有数据库: show databases; ---默认数据库: mysql - 用户权限相关数据 ...
- Swift3.0P1 语法指南——构造器
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Python之美--Decorator深入详解
转自:http://www.cnblogs.com/SeasonLee/archive/2010/04/24/1719444.html 一些往事 在正式进入Decorator话题之前,请允许我讲一个小 ...
- Normalization
In creating a database, normalization is the process of organizing it into tables in such a way that ...
随机推荐
- javaScript_BOM浏览器对象模型
BOM:浏览器对象模型 Browser Object Model 用来访问和操作浏览器窗口,使JavaScript有能力与浏览器对话 通过使用BOM ,可以移动窗口,更改状态栏.执行其他不与页面内容发 ...
- Git 小课堂 002——别名
昨天我们聊了聊 Git 的文件存储,今天我们聊聊 Git 的别名.不知道你是不是熟悉别名,如果你经常使用命令行做一些事情,有一些复杂的命令,或者是一些简单的操作,往往用一些别名方法就很方便很容易,下面 ...
- dockerfile---apt-get install vim 时 Unable to locate package vim
在学习 dockerfile 的时候,发现编写的 Dockerfile 中的 apt-get install 命令无法找到要安装的包,所以记录一下这次发生的错误. 环境:宿主机:windows 10 ...
- 2020/1/27代码审计学习之SQL注入漏洞
PHP代码审计SQL注入漏洞 0x00 首先明确什么是SQL注入,SQL语句必须掌握. 常见的注入总的来说可以分为两大类:数字型和字符型. 这两类中包含了诸如报错注入,宽字节注入,盲注,二次注入,co ...
- css中标签总结
cursor CSS属性定义鼠标指针悬浮在元素上方显示的鼠标光标cursor:pointer: 小手 cursor:wait:等待....很多种 <span contenteditable=&q ...
- 4. 现代 javascript class 专题 和 异步专题
class 专题 定义 class //es5 类的定义 属性定义在 function 上, 方法定义在原型链上 function foobar(){ this.foo_ = 'foo'; this ...
- c# 多线程——入门学习
1. 概念介绍 1.1 线程 线程是操作系统能够进行运算调度的最小单位,包含在进程之中,是进程中的实际运作单位.一条线程指的时进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不 ...
- Django框架(八):视图(一) URLconf、视图
1. 视图 视图的功能就是接收请求,进行处理,与M和T进行交互,返回应答. 返回html内容HttpResponse,也可能重定向redirect,还可以返回json数据. 1.1 URLconf 1 ...
- php分页代码。
$result_count=select("hy_news_en",$where,'','','count(1)'); $count=mysql_fetch_array( ...
- 61)普通类的.h和.cpp分离
//标头.h文件 //这个是在C中这样写 #ifndef HH_01//开始写小写 hh_01 然后选中这个 crtl+shift+u 就变成大写了 #define HH_01 #endif //在C ...