HDU 1171 Big Event in HDU(01背包)
in HDU 01 Event 背包 Big
2023-09-14 09:06:21 时间
题目地址:HDU 1171
还是水题。
。
普通的01背包。注意数组要开大点啊。
。。。
代码例如以下:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include <set> #include <algorithm> using namespace std; int dp[260000], v[600], k[600], c[260000]; int main() { int n, i, j, y, z, sum, s, cnt, x; while(scanf("%d",&n)!=EOF) { if(n<0) break; sum=0; for(i=0;i<n;i++) { scanf("%d%d",&v[i],&k[i]); sum+=v[i]*k[i]; } memset(dp,0,sizeof(dp)); cnt=0; for(i=0;i<n;i++) { x=k[i]; y=1; while(x-y>=0) { c[cnt++]=y*v[i]; x-=y; y*=2; } if(x) c[cnt++]=x*v[i]; } s=sum; sum/=2; dp[0]=1; for(i=0;i<cnt;i++) { for(j=sum;j>=c[i];j--) { if(dp[j-c[i]]) dp[j]=1; } } int ans; for(i=sum;i>=0;i--) { if(dp[i]) { ans=i; break; } } printf("%d %d\n",s-ans,ans); } return 0; }
相关文章
- VUE - vue.runtime.esm.js?6e6d:619 [Vue warn]: Do not use built-in or reserved HTML elements as component i
- [XState + React] using @xstate/inspect to display state machine char in webapp
- [Netlify serverless] Dependencies are not automatically install in functions
- [XState] Simplify State Explosion in XState through Hierarchical States
- [React] Understanding setState in componentDidMount to Measure Elements Without Transient UI State
- [Docker] Storing Container Data in Google Cloud Storage
- 【转】You Can Now Use OneDrive in Linux Natively Thanks to Insync
- Execution error: 'the function name is not a recognized built-in function name'
- How is account image maintained in CRM rendered in Fiori
- SAP Enterprise search test report ESH_TEST_SEARCH debug in Q2D
- where is field waerk in pricing structure filled
- Business Partner Relationship Category in CRM and C4C
- 【hdu 6342】Expression in Memories
- 【hdu 1847】Good Luck in CET-4 Everybody!
- Reuse library debug in Chrome - phase3 exchange drop down list
- 成功解决logging in emit stream.write(msg+self.terminator) ValueError:underlying buffer has been detached
- 【人工智能】所有语言模型都需要位置编码吗? Is Positional Encoding Required In All Language Models?
- HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
- [git] fatal: This operation must be run in a work tree
- entify framework MySql Unknown column ‘Extent1.Discriminator‘ in ‘field list‘