标签:blog mos idt while safe ret sse 数组 namespace
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3148 | Accepted: 851 |
Description
Input
Output
Sample Input
3 15 1 10 20
Sample Output
11
Hint
#include<iostream> #include <stdio.h> #include <algorithm> #include <string.h> using namespace std; typedef long long ll; int a[1005]; ll sum[1005]; ll ans,m,n; void dfs(ll x, ll cnt) { if(cnt>ans) ans=cnt; if(x<1) return ; for(int i =x;i>=1;i--) { if(cnt+sum[i]<=ans) continue; if(cnt+a[i]>m) continue; dfs(i-1,cnt+a[i]); } } int main() { while(~scanf("%lld%lld",&n,&m)) { ans=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; } dfs(n,0); printf("%lld",ans); } }
POJ--3172 Scales (DFS 大容量背包 C++)
标签:blog mos idt while safe ret sse 数组 namespace
原文地址:http://www.cnblogs.com/ygtzds/p/7384612.html