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 ...
随机推荐
- ms sqlserver 清除数据库日志脚本
USE [master] GO ALTER DATABASE F360DW SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE F360DW SET ...
- 牛客网Java刷题知识点之抽象类与接口
不多说,直接上干货! 接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 抽象类与接口是Java语言中对抽象概念进行定义的两种机制,正是由于它们的存在才赋予java强大的面向对象的能力. ...
- 解决Linux下SSH等终端乱码问题
1.vi /etc/sysconfig/i18n Centos5.5原来内容是: //LANG="en_US.UTF-8" //SYSFONT="latarcyrheb- ...
- UWP开发:自动生成迷宫&自动寻路算法(3)
+ , + ];//0<=x<=12 0<=y<=24 private static Random Rd = new Random(); 首先声明mazeMap存储数据,声明了 ...
- [VC]在VC++中实现让程序只运行一个实例的方法且实现该实例
方法一: 有时候在开发应用程序时,希望控制程序运行唯一的实例.例如,最常用的mp3播放软 件Winamp,由于它需要独占计算机中的音频设备,因此该程序只允许自身运行唯一的一个例程.在Visual C+ ...
- 2015 ACM/ICPC Asia Regional Changchun Online Pro 1008 Elven Postman (BIT,dfs)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- SC || Git 相关知识
发现大佬的博客:https://www.cnblogs.com/onetwo/p/4157610.html 注:图片来自小姐姐的笔记~ ┉┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉┉┉┉∞ ∞┉┉┉┉∞ ...
- 7.Props向子组件传递数据
组件实例的作用域是孤立的.这意味着不能并且不应该在子组件的模板内直接引用父组件的数据. 可以使用 props 把数据传给子组件. for-child-msg="aaa" , fo ...
- c#和Java中的继承
c#和Java: 1.首先,子类继承了父类的属性和方法,但是子类并没有继承父类的私有字段. 2.子类并没有继承父类的构造函数,但是.子类会默认的调用父类无参数的构造函数,创建父类对象,让子类可以使用父 ...
- ovx openVirtex安装
搞了好久的pox实验,中途一个星期没更新了吧, 今天继续... 新手第一次搞还是在虚拟机上最安全~ ovx参照上面的做吧,注意必须在联网的情况下,否则很多控件都连不上(第一次做的时候虚拟机没配ip 坑 ...