3 条题解
-
1赵青海 (huhe) LV 7 SU @ 2021-8-7 21:05:12
C++ :
#include <iostream> #include <ctime> #include <algorithm> using namespace std; int n,w; int c[19]; int use[19]; int minn = 20; bool cmp(int x,int y) { return x>y; } void dfs(int pos,int tot) { if(tot>minn) return ; if(pos == n+1) { minn = min(minn,tot); return ; } for(int i=1;i<=tot;i++) { if(c[pos] + use[i] <= w) { use[i] += c[pos]; dfs(pos+1,tot); use[i] -= c[pos]; } } use[tot+1] = c[pos]; dfs(pos+1,tot+1); use[tot+1] = 0; } int main() { cin>>n>>w; for(int i=1;i<=n;i++) cin>>c[i]; // clock_t start = clock(); sort(c+1,c+1+n,cmp); dfs(1,0); // clock_t end = clock(); cout<<minn<<endl; // cout<<end-start<<endl; return 0; }
Python :
# coding=utf-8 a,b=map(int,input().split()) n=0 cnt=0 for x in range(a): n=int(input()) cnt+=n if(int(cnt/b)==cnt/b): print(int(cnt/b)) else: print(int(cnt/b)+1)
-
-62021-11-29 17:48:36@
11
-
-62021-11-29 17:36:29@
# coding=utf-8 a,b=map(int,input().split()) n=0 cnt=0 for x in range(a): n=int(input()) cnt+=n if(int(cnt/b)==cnt/b): print(int(cnt/b)) else: print(int(cnt/b)+1)
- 1
信息
- ID
- 76
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 290
- 已通过
- 74
- 上传者