积木城堡
来源:互联网 发布:unity3d 摇杆控制角色 编辑:程序博客网 时间:2024/04/28 09:36
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=110;
int f[maxn][maxn],n,dp[110][10010],cnt[maxn],s[maxn],d[maxn][maxn];
int main(){
scanf("%d",&n);
int maxx=-1;
for(int i=1;i<=n;i++){
int x;
while(cin>>x){
if(x==-1) break;
d[i][++cnt[i]]=x;
s[i]+=x;
}
if(s[i]>maxx) maxx=s[i];
}
for(int i=1;i<=n;i++) dp[i][0]=true;
for(int i=1;i<=n;i++){
for(int j=1;j<=cnt[i];j++){
for(int k=0;k<=s[i];k++){
if(k-d[i][j]>=0){
if(dp[i][k-d[i][j]]) dp[i][k]=true;
}
}
}
}
int flag=false;
for(int i=maxx;i>=1;i--){
int cur=0;
for(int j=1;j<=n;j++){
if(dp[j][i]){
++cur;
}
}
if(cur==n){
cout<<i<<endl;
return 0;
}
}
cout<<0<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=110;
int f[maxn][maxn],n,dp[110][10010],cnt[maxn],s[maxn],d[maxn][maxn];
int main(){
scanf("%d",&n);
int maxx=-1;
for(int i=1;i<=n;i++){
int x;
while(cin>>x){
if(x==-1) break;
d[i][++cnt[i]]=x;
s[i]+=x;
}
if(s[i]>maxx) maxx=s[i];
}
for(int i=1;i<=n;i++) dp[i][0]=true;
for(int i=1;i<=n;i++){
for(int j=1;j<=cnt[i];j++){
for(int k=0;k<=s[i];k++){
if(k-d[i][j]>=0){
if(dp[i][k-d[i][j]]) dp[i][k]=true;
}
}
}
}
int flag=false;
for(int i=maxx;i>=1;i--){
int cur=0;
for(int j=1;j<=n;j++){
if(dp[j][i]){
++cur;
}
}
if(cur==n){
cout<<i<<endl;
return 0;
}
}
cout<<0<<endl;
return 0;
}
阅读全文
0 0
- 积木城堡
- 积木城堡
- 积木城堡
- 积木城堡
- 积木城堡 题解
- tyvj p1190 积木城堡
- 【动态规划】 积木城堡
- VIJOS P1059 积木城堡
- 积木城堡_DP
- vijos 1059 积木城堡
- vijos P1059积木城堡
- P1059 积木城堡
- vijosP1059 积木城堡
- Vijos P1059 积木城堡
- [ZJOI2001] 积木城堡
- P1504 积木城堡
- 洛谷 P1504 积木城堡
- vijos1059 积木城堡(背包)
- Vijos P1212 Way Selection
- tomcat报错:Error parsing HTTP request header
- [BZOJ4152]The Captain
- [BZOJ3040]最短路
- [BZOJ1857][SCOI2010]传送带
- 积木城堡
- 读《清单革命》
- [BZOJ4576]262144 分治/区间DP
- BZOJ1051(HAOI2006)[受欢迎的牛]--并查集+Tarjan
- Alpha-go有了新版本:能自己对弈
- 你们想要的 Tumblr 爬虫
- codevs 1069 [NOIP2010] 关押罪犯 二分+二分图染色
- 洛谷1563(NOIP2016)[玩具谜题]--模拟
- java线程池