Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)
2015-10-04 18:21
459 查看
A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j],
将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][k]+B[k][j])。非法的情况标记为-INF,用倍增加速。
将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][k]+B[k][j])。非法的情况标记为-INF,用倍增加速。
#include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 101; int n; typedef int MType; struct Matrix { MType dat[maxn][maxn]; MType *operator [](int x){ return dat[x]; } Matrix operator | (Matrix& B) { Matrix re; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ re[i][j] = -INF; for(int k = 0; k < n; k++){ re[i][j] = max(re[i][j],dat[i][k]+B[k][j]); } } } return re; } Matrix operator ^ (int q){ Matrix Re, A = *this; memset(Re.dat,0,sizeof(Re.dat)); while(q){ if(q&1){ Re = Re | A; } A = A | A; q >>= 1; } return Re; } }; int a[maxn]; //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int T; scanf("%d%d",&n,&T); for(int i = 0; i < n; i++){ scanf("%d",a+i); } Matrix A; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(a[i]>a[j] ) A[i][j] = -INF; else { A[i][j] = 1; for(int k = 0; k < j; k++){ if(a[k] <= a[j]) A[i][j] = max(A[i][j],A[i][k]+1); } } } } A = A^T; int ans = 0; for(int i = 0; i < n;i++){ for(int j = 0; j < n; j++){ ans = max(ans,A[i][j]); } } printf("%d\n",ans); return 0; }
相关文章推荐
- codeforces 22B B. Bargaining Table(dp)
- LeetCode -- Factorial Trailing Zeroes
- Codeforces Round #323 (Div. 1) B. Once Again... 暴力
- codeforce 583D Once Again... - 最长上升子序列
- 唤醒 -- try_to_wake_up() http://blog.csdn.net/linux__kernel/article/details/1476795
- http://www.bubuko.com/infodetail-425054.html try_to_wake_up()
- Centos下apache启动时httpd: apr_sockaddr_info_get() failed for 报错
- linux 惊群问题 http://blog.csdn.net/liujiyong7/article/details/43346829
- 错误: 无法找到或可以不被加载到主类 Main
- 海量数据处理常用思路和方法 http://blog.csdn.net/lmh12506/article/details/7563266
- poll函数源码详细分析 http://blog.csdn.net/lmh12506/article/details/7556297
- CF#323-DIV2-D. Once Again-暴力贪心LIS
- TCP协议发送SKB时ip_summed成员的设置 http://blog.csdn.net/justlinux2010/article/details/8508455
- epoll源码分析---sys_epoll_wait()函数 http://blog.csdn.net/hbhhww/article/details/7746638
- 【bzoj1260】【CQOI2007】【涂色paint】【dp】
- unknown host www.baidu.com network is unreachable
- kernel painic not syncing
- Software caused connection abort: recv failed
- Hadoop Failed to set permissions of path
- Failed to set permissions of path:\tmp\hadoop-yth\mapred\staging\yth-2036315919\.staging to 0700