uva 10827 Maximum sum on a torus
来源:互联网 发布:javascript创建表格 编辑:程序博客网 时间:2024/04/28 14:56
题意:此题是uva 108 Maximum Sum的升级版,原本只是求矩阵内的最大和,现在这个矩阵可以构成一个环。
思路:枚举矩阵的宽度,从i到j,然后将矩阵转化为一维,接下来就是如何在一个环上求最大连续和了。
#include <iostream> #include <climits>using namespace std;int n;int a[100][100];int b[100];int dp[100];void input(){cin>>n;for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cin>>a[i][j];}}}int solve(){int maximum = INT_MIN;for(int i = 0; i < n; i++){//枚举宽度,从第i列到第j列 for(int j = 0; j < n; j++){if(i == j+1)continue;for(int l = 0; l < n; l++){//化成一维 b[l] = 0;for(int k = i; k != j+1; k++){if(k >= n)k %= n;b[l] += a[l][k];}dp[l] = b[l];}for(int l = 0; l < n; l++){//枚举dp起点 int cnt = 0;for(int k = l+1; cnt < n-1; k++,cnt++){if(k >= n)k %= n;if(k == 0){if(dp[n-1]+b[0]>dp[0])dp[0] = dp[n-1]+b[0];}else{if(dp[k-1]+b[k]>dp[k])dp[k] = dp[k-1]+b[k];}}for(int k = 0; k < n; k++){if(dp[k] > maximum)maximum = dp[k];dp[k] = b[k];}}}}return maximum;}int main(){int t;cin>>t;for(int i = 0; i < t; i++){input();cout<<solve()<<"\n";}return 0;}
0 0
- UVa 10827 - Maximum sum on a torus
- UVa 10827 - Maximum sum on a torus
- uva 10827 - Maximum sum on a torus
- Maximum sum on a torus Uva 10827
- Uva-10827-Maximum sum on a torus
- uva 10827 - Maximum sum on a torus
- UVA - 10827 Maximum sum on a torus
- UVa:10827 Maximum sum on a torus
- UVa 10827 - Maximum sum on a torus
- UVA 10827 - Maximum sum on a torus
- UVA--10827 Maximum sum on a torus
- uva 10827 Maximum sum on a torus
- UVa 10827 - Maximum sum on a torus
- UVA 10827Maximum sum on a torus
- UVA 10827 Maximum sum on a torus .
- UVa 10827 Maximum sum on a torus
- uva 10827Maximum sum on a torus
- uva 10827 - Maximum sum on a torus(dp)
- codeforces Riding in a Lift
- 【数值分析】误差的分析与减少及Matlab解线性方程的四种方法
- [GO]HTTP 请求实例(GET)以及设置代理
- ubuntu下安装R
- Nginx + Apache 配置反向代理和静态资源缓存
- uva 10827 Maximum sum on a torus
- svm
- 百度地图定位经纬度
- 矩阵乘法
- 【BZOJ】【P3707】【圈地】【题解】【乱搞】
- 【web++_第四阶段_(security后)学做精美前台_1】
- ABAP--HR的工资计算样例代码
- java中的Class类
- Python标准库:内置函数locals()