ural 1244
来源:互联网 发布:运行单独的java文件 编辑:程序博客网 时间:2024/05/20 18:20
PRO IS HERE
简单的背包问题,输出yy一下就可以了。
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<set>#include<queue>#include<map>using namespace std;#define PB push_back#define INS insert#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define nMax 100001#define bug puts("Fuck");#define LL long long#define pb push_backint n;int dp[nMax],fa[nMax],vis[nMax];int a[nMax],V;void sovle(){dp[0] = 1;FOR(i,1,V) dp[i] = fa[i] = 0;FOR(i,1,n) DOR(j,V,0) if(j>=a[i]) dp[j] += dp[j-a[i]];if(dp[V] > 1) {printf("-1\n");}else if(dp[V] == 0) {printf("0\n");}else{FOR(i,1,V) dp[i]=fa[i]=0;FOR(i,1,n) DOR(j,V,0) if(dp[j]==0 && j>=a[i] && dp[j-a[i]]) dp[j]=1,fa[j]=i; FOR(i,1,n) vis[i] = 0;while(V){if(fa[V] > 0) vis[fa[V]] = 1;V -= a[fa[V]];}bool first = 1 ;FOR(i,1,n)if(!vis[i]){ if(first) first=false;else printf(" ");printf("%d",i);}printf("\n");}}int main(){#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin);#endif//freopen("output.txt","w",stdout);while(~scanf("%d",&V)){scanf("%d",&n);FOR(i,1,n) scanf("%d",&a[i]);sovle();}return 0;}
- ural 1244
- URAL 1244
- URAL 1244 Gentlemen
- URAL
- 【ural】
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- UITextField
- Bitmap Indexes and Deadlocks: Deadlocks on DML's and DDL's [ID 171795.1]
- 程序员中的其他程序员
- yum包的简单应用(一)——制作自己的源createrepo
- (代码6)卷积
- ural 1244
- x264基于经验和感觉的码率控制策略
- kernel与用户层接口之字符设备接口
- yum包的简单应用(二)——实验
- 负载均衡技术讨论
- H.264 Profile、Level、Encoder三张简图
- TinyOS下的makefile(持续更新)
- 取url扩展名
- 在Windows下使用OpenCL