大奖赛
来源:互联网 发布:js input不可编辑属性 编辑:程序博客网 时间:2024/04/30 09:57
30暴力搜
60 01背包
100 折半搜索
以上三个做法都很裸
顺便Lancelot+Morgan
长江骑士和王姐 怕不是某呆毛王要提着咖喱棒来打架
60分背包
忘了+0
结果一直少1
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<climits>#include<queue>#define LL long longusing namespace std;int n,k,i,j,pr[45];LL dp[10005];int main(){ freopen("champion.in","r",stdin); freopen("champion.out","w",stdout); scanf("%d%d",&n,&k); for(i=1;i<=n;i++) scanf("%d",&pr[i]); dp[0]=1; for(i=1;i<=n;i++) for(j=k;j>=pr[i];j--) dp[j]+=dp[j-pr[i]]; for(i=0;i<k;i++) dp[k]+=dp[i]; printf("%lld",dp[k]); return 0;}
100分正解
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<climits>#include<cstdlib>#include<ctime>#include<cstring>#include<queue>#define LL long longusing namespace std;LL tot1,sum1[1100000],n1,n2,n,k,ans,a[45];void dfs1(LL x,LL tot){ if(x==n1+1) { tot1++; sum1[tot1]=tot; return; } if(tot+a[x]<=k) dfs1(x+1,tot+a[x]); dfs1(x+1,tot);}void dfs2(LL x,LL tot){ if(x==n+1) { LL p,pos; p=k-tot; pos=upper_bound(sum1+1,sum1+tot1+1,p)-sum1; ans+=pos-1; return; } if(tot+a[x]<=k) dfs2(x+1,tot+a[x]); dfs2(x+1,tot);}void predfs1(){ n1=n/2; dfs1(1,0); sort(sum1+1,sum1+tot1+1);}void predfs2(){ n2=n-n1; dfs2(n1+1,0);}int main(){ freopen("champion.in","r",stdin); freopen("champion.out","w",stdout); LL i; scanf("%lld%lld",&n,&k); for(i=1;i<=n;i++) scanf("%lld",&a[i]); predfs1(); predfs2(); printf("%lld",ans); return 0;}
阅读全文
0 0
- 大奖赛
- 歌星大奖赛
- 歌星大奖赛
- 大奖赛计分
- 大奖赛计分
- 大奖赛计分。
- 大奖赛积分
- 大奖赛计分
- 大奖赛计分
- 歌星大奖赛
- 歌手大奖赛
- 大奖赛积分
- 大奖赛计分
- 大奖赛计分
- 大奖赛计分
- 歌星大奖赛
- 大奖赛计分
- 大奖赛积分
- Java内存区域与内存溢出异常
- Spring Cloud Sleuth (2)-与ELK集成
- JDK1.7的新特性
- MindManager2018,双11走在人前!
- js或php压缩图片
- 大奖赛
- java.lang.Long cannot be cast to java.lang.String
- 人机交互新进展:LFR-DFSMN语音识别声学模型介绍
- js模拟点击,关闭父页面
- Tomcat多端口&虚拟目录配置
- 垃圾收集器与内存分配策略
- JSON-RPC 2.0 规格翻译
- javascript学习笔记
- 微信企业号获取用户授权登陆信息