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 ...
随机推荐
- 文献阅读报告 - Pedestrian Trajectory Prediction With Learning-based Approaches A Comparative Study
概述 本文献是一篇文献综述,以自动驾驶载具对外围物体行动轨迹的预测为切入点,介绍了基于运动学(kinematics-based)和基于机器学习(learning-based)的两大类预测方法. 并选择 ...
- UVA 12663 第九届省赛 高桥与低桥 线段树
题意很简单,n个桥的高度是事先给出来的,然后有m次涨水与落水的高度,问有多少座桥在这m次涨落之后 被淹超过了k次,如果某桥本身被水淹了,此时再涨水,就不能算多淹一次 看下数据10的五次方,10的五次方 ...
- css选择器,选择指定属性的值
选择属性为href的值: <a class='test' href='www.baidu.com' >test</a> response.css('.test::attr(hr ...
- Python 重新加载模块
每个Python文件中的import modulename只被加载一遍,如果在运行过程中,这个Module被更改了,即使在在interpretor中运行import 语句也没用. 可以使用import ...
- 2019年春PAT甲级考试
这次考试不是很理想,一道题目没能做完. 自己原因差不多三条: 1.自己实力不够,准备时间也有点仓促,自己没能做到每道题目都有清晰的思路. 2.考试的心理素质不行,因为设备原因东奔西跑浪费了挺多时间,自 ...
- 1811 06 pygame 的继续开发
早上看了 高数和python 好像系统没有保存 桑心啊 关于游戏背景的制作 游戏背景就是 背景在移动 而主人物还在原位置的 常常用于跑酷游戏类 背景开始绘制两张图像 一张完全 ...
- Windows下将Python源代码.py文件封装成exe可执行文件方法
安装pyinstaller cmd中使用pip安装 pip install pyinstaller 同时会自动安装pywin32(pip真慢50M这里就走20KB),可以进行切换为国内源进行提速. 就 ...
- 基本 Python 词汇
本文档介绍了要理解“使用 Python 进行地理处理”的帮助文档需要掌握的一些词汇. ! 术语 说明 Python Python 是由 Guido van Rossum 在上世纪八十年代末构想并 ...
- java读取本地json数组并解析
1.本地json位置 2,json数据 {"garbages":[{"id":"/m/011k07","ename":& ...
- 面向对象 part7 class
类的定义 类实际上是个“特殊的函数“,就像能够定义函数表达式和函数声明一样,类语法 有两个组成部分:类表达式和类声明式 类声明 类声明没有提升 静态方法 只有构造函数名可以调用,实例无法使用.常用于应 ...