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的更多相关文章

  1. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

    题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution

    A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...

  7. 计蒜客 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  ...

  8. 计蒜客 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. ...

  9. 计蒜客 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 ...

随机推荐

  1. (转)磁盘阵列RAID原理、种类及性能优缺点对比

    磁盘阵列RAID原理.种类及性能优缺点对比 原文:http://www.cnblogs.com/chuncn/p/6008173.html 磁盘阵列(Redundant Arrays of Indep ...

  2. 《深入理解java虚拟机》笔记(3)实战:OutOfMemoryError异常

    一.Java堆溢出 测试代码: /** * <p>Java堆异常测试</p> * <code>VM Args: -Xms20m -Xmx20m -XX:+HeapD ...

  3. JS filter使用

    filter 用于筛选数组中符合条件的所以元素,filter只能接受函数 注意:filter只返回筛选结果,不会对原来数组改变 实现方法: <html lang="en"&g ...

  4. 【持续更新】Spring相关

    什么是IoC 什么是AoP Bean的实例化方法--3种 Bean的作用域--常用2种 Bean的生命周期 Bean的装配方式 基于xml的2种装配方式 基于Annotaton的装配方式

  5. 记录:swift学习笔记1-2

    swift还在不断的更新做细微的调整,都说早起的鸟儿有虫吃,那么我们早点出发吧,趁着国内绝大多数的coder们还没有开始大范围普遍应用. 网上有些大神说:swift很简单!我不同意这个观点,假如你用h ...

  6. 零基础逆向工程19_PE结构03_代码节空白区添加代码_shellcode

    1.获取MessageBox地址,构造ShellCode代码 三种获取方法,参考文章末的一篇帖子. E8 E9计算公式 call 的硬编码:E8 00 00 00 00 jmp 的硬编码:E9 00 ...

  7. Windows Azure 配置Active Directory 主机(2)

    前一篇概况给大家介绍了,在云端部署一台DC 需要满足一些条件,接下来进入正题,云端VM安装域控制器具体步骤. 步骤1 :验证 主DC 的静态 IP 地址 1.登录到 Corp 网络上的 主DC. 2. ...

  8. PHP的优良习惯(转)

    1.多阅读手册和源代码 没什么比阅读手册更值得强调的事了–仅仅通过阅读手册你就可以学习到很多东西,特别是很多有关于字符串和数组的函数.就在这些函数里面包括许多有用的功能,如果你仔细阅读手册,你会经常发 ...

  9. HTML_6 (表单应用)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 《队长说得队》【Alpha】Scrum meeting 2

    项目 内容 这个作业属于哪个课程 >>2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 >>实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 ...