The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt
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 Bcolor 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.
Input Format
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 MM lines with each line MM integers. The j^{th}jth integer in the i^{th}ith line means [i][j] 1≤f[i][j]≤1000000).
There are no more than 1010 test cases.
Output Format
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
题目来源
The 2018 ACM-ICPC China JiangSu Provincial Programming Contest
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
/*
f[a][b]+f[b][c]+f[c][d]+……+f[y][z]的最大值。(n-1项)
n=2 :二重循环
n=3 :三重循环
n=4 : f[a][b]+f[b][c]+f[c][d]
可以用f[a][c]来代替f[a][c]和f[a][b]+f[b][c]的较大值,在进行f[a][c]+f[c][d]
此时的f[a][c]表示第一天a,第三天c的最大值
n>=5的依此类推
那么可以利用矩阵快速幂的思想,因为(n-2)*m^2会超时
n=2要更新一次来找最大值,n=3就要更新2次。
因此n要更新n-1次。
*/
const int N=;
ll f[N][N],n,m;
struct ma{
ll m[N][N];
ma(){
memset(m,,sizeof(m));
}
};
ll MAX;
ma poww(ma a,ma b)
{
ma c;
for(int i=;i<m;i++)
{
for(int j=;j<m;j++)
{
for(int k=;k<m;k++)
{
c.m[i][j]=max(c.m[i][j],a.m[i][k]+b.m[k][j]);
}
}
}
return c;
}
ma qu(ma a,ll n){
ma c;
while(n){
if(n&) c=poww(c,a);
n>>=;
a=poww(a,a);
}
return c;
}
int main()
{
while(~scanf("%lld%lld",&n,&m)){
ma ans;
for(int i=;i<m;i++)
{
for(int j=;j<m;j++)
{
scanf("%lld",&ans.m[i][j]);
}
}
ans=qu(ans,n-);
MAX=;
for(int i=;i<m;i++){
for(int j=;j<m;j++)
{
MAX=max(MAX,ans.m[i][j]);
}
}
printf("%lld\n",MAX);
}
return ;
}
The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt的更多相关文章
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元
题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest J. Set
Let's consider some math problems. JSZKC has a set A=A={1,2,...,N}. He defines a subset of A as 'Meo ...
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest(第六场)
A Plague Inc Plague Inc. is a famous game, which player develop virus to ruin the world. JSZKC wants ...
- C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest
We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Give ...
- B.Grid with Arrows-The 2019 ICPC China Shaanxi Provincial Programming Contest
BaoBao has just found a grid with $n$ rows and $m$ columns in his left pocket, where the cell in the ...
- ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution
A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...
- 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered ...
- 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛
Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
随机推荐
- DOM所有的命令(CMD)
刚接触电脑的时候是从DOS系统开始,DOS时代根本就没有Windows这样的视窗操作界面,只有一个黑漆漆的窗口,让你输入命令.所以学DOS系统操作,cmd命令提示符是不可或缺的.可以告诉大家,大多数的 ...
- <Android 应用 之路> 天气预报(三)
昨天介绍了基本的载入界面,今天介绍下天气信息显示界面的代码 基本ListView显示 搜索框,查询城市 上一篇文章中,载入界面通过showWeatherInfo()方法跳转到天气信息显示界面 priv ...
- 安卓中Paint类和Canvas类的方法汇总
Paint类的常用的方法 1.setColor方法,用于设置画笔的颜色,public void setColor(int color)//参数color为颜色值,也可以使用Color类定义的颜色Col ...
- 对Yii 2.0模型rules的理解(load()无法正确装载数据)
在实际开发中,遇到数据表新增字段而忘记了在对应模型中rules规则中添加新增的字段,而导致load()方法装载不到新增字段,导致新增字段无法写入数据库中. 解决办法:在新增字段后及时在对应模型ru ...
- html 之table标签结构学习
一.HTML table标签结构 html 中table标签的结构情况,如下所示: <!-- table标签结构如下: <table> <thead> # thead表格 ...
- python基础教程总结10——文件
1.打开文件 open(name[mode[,buffing]) 参数: 文件,模式,缓冲 1)name: 是强制选项,模式和缓冲是可选的 #如果文件不在,会报下面错误1 >>&g ...
- gzip, gunzip, zcat - 压缩或展开文件
总揽 gzip [ -acdfhlLnNrtvV19 ] [-S 后缀] [ 文件名 ... ] gunzip [ -acfhlLnNrtvV ] [-S 后缀] [ 文件名 ... ] zcat [ ...
- NBear简介与使用图解
NBear简介与使用图解 框架类型:ORM映射框架 简介:NBear是一个基于.Net 2.0.C#2.0开放全部源代码的的软件开发框架类库.NBear的设计目标是尽最大努力减少开发人员的工作量,最大 ...
- k8s1.13.0二进制部署-node节点(四)
Master apiserver启用TLS认证后,Node节点kubelet组件想要加入集群,必须使用CA签发的有效证书才能与apiserver通信,当Node节点很多时,签署证书是一件很繁琐的事情, ...
- c#中接口、抽象类、继承综合小练习
namespace Test { class Program { static void Main(string[] args) { //作业:橡皮rubber鸭子.木wood鸭子.真实的鸭子real ...