UVALive - 7484 Association for the Country of Mububa(dp)
来源:互联网 发布:用python进行数据分析 编辑:程序博客网 时间:2024/04/28 10:37
题意就是给你一些数,将这些数划分成n个区间,使得后一个区间里数字的和大于等于前一个区间里数字的和,求n最大;
#include<bits/stdc++.h>#include<string.h>#include<string>#include<cstring>#include<stdio.h>#include<set>#include<vector>#include<algorithm>using namespace std;#define ll long long#define mod 1000000007 int dp[3005];//最大区间数 ll sum[3005];//前缀和 ll ism[30005];//第i个区间最大的值 int main(){ int n; while(cin>>n) { memset(dp,0,sizeof(dp)); memset(sum,0,sizeof(sum)); memset(ism,0,sizeof(ism)); for(int i=1;i<=n;i++) { int a; cin>>a; sum[i]=sum[i-1]+a; } for(int i=1;i<=n;i++) { for(int j=i-1;j>=0;j--) { if(sum[i]-sum[j]>=ism[j])//i到j区间的数字之和大于等于到第j个数字为止的最后一个区间的和; { dp[i]=dp[j]+1; ism[i]=sum[i]-sum[j]; break; } } } cout<<dp[n]<<endl; } return 0;}
0 0
- UVALive - 7484 Association for the Country of Mububa(dp)
- uvalive 7480 Association for Control Over Minds
- The Psychology of Cross Country
- The Psychology of Cross Country
- The Psychology of Cross Country
- UVALive 6680 Join the Conversation (DP)
- UVALive 3637 The Bookcase(DP)
- UVAlive 7487 Association of Cats and Magical Lights(线段树)
- The Six Types of Rails Association
- UVALive 7661The Size of the Smallest Hole(dfs)
- UVALive-3637 The Bookcase(DP)
- 【UVALive 7505】Hungry Game of Ants(DP)
- UVALive 6919 A game for kids(树形dp)
- 【瞎搞】 HDU 3101 The Heart of the Country
- HDOJ3101 LA4226 The Heart of the Country 简单模拟
- 原来国家的名字可以如此浪漫(the Romantic Name of a Country)
- UVALive 3942 Remember the Word(trie + dp)
- UVAlive 6560 - The Urge to Merge(状压dp)
- [HDU 5818] Joint Stacks (脑洞+实现)
- 211.leetcode Add and Search Word - Data structure design(medium)[Trie树]
- iOS-图片显示时失真问题
- instanceof 用法及作用
- Lua
- UVALive - 7484 Association for the Country of Mububa(dp)
- 高效的加载大分辨率的图片 bitmap
- 大数运算和大数类
- HttpClient4 学习分享总结
- 细说Angular ng-class
- ubuntu启动器移动到桌面底部
- 189. Rotate Array*
- HDU 3664 Permutation Counting (DP)
- 木棒拼图(multiset 的应用)----今日头条2017后端工程师实习生笔试题