(2019 GDUT Rating Contest #I)G. Back and Forth
2019-03-16 01:11
295 查看
传送门
题目大意:
农夫有两个谷仓,10桶不同大小的桶。星期一,农夫在两个谷仓放了1000L的牛奶。 星期二,他从一个谷仓装满一桶牛奶,送到另外一个谷仓并把桶留在这个谷仓。如此重复,问星期五时第一个谷仓会有多少种不同存量的牛奶?
题目分析:
这里dfs可以做,我这里 dfs 记录了 r第一个谷仓的牛奶量,n1第一个谷仓桶的数量,n2第二个谷仓桶的数量,day第几天。
如果他从第一个谷仓拿了桶【i】,则将这个桶【i】标记为不能使用,然后存第二个谷仓的桶的数组就要把这个桶【i】加进去。
这里 dfs 还要记得回溯,不然无法遍历所有情况。
其他dalao都是值传几个参数的,就我传得最多(发出菜鸡的叫声)。
代码:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int b1[20],v1[20]; int b2[20],v2[20]; int vis[10000]; int cnt=0; void dfs(int r,int n1,int n2,int day){ if(day==6){ if(vis[r]==0){ vis[r]=1; cnt++; } return; } if(day%2==0){ for(int i=0;i<n1;i++){ if(v1[i]==1||b1[i]==0) continue; v1[i]=1;b2[n2]=b1[i]; dfs(r-b1[i],n1,n2+1,day+1); v1[i]=0;b2[n2]=0; } } else{ for(int i=0;i<n2;i++){ if(v2[i]==1||b2[i]==0) continue; v2[i]=1;b1[n1]=b2[i]; dfs(r+b2[i],n1+1,n2,day+1); v2[i]=0;b1[n1]=0; } } return; } int main(){ for(int i=0;i<10;i++)scanf("%d",&b1[i]); for(int i=0;i<10;i++)scanf("%d",&b2[i]); dfs(1000,10,10,2); cout<<cnt<<endl; return 0; }
相关文章推荐
- R1_G_Back and Forth
- Back and Forth
- Back and Forth 递推
- codeforces G. Back and Forth(暴力)
- Back and Forth
- AtCoder - 2282 Back and Forth (思维)
- G. Back and Forth(dfs)
- Back and Forth
- [USACO18DEC]Back and Forth(G题)
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
- AtCoder 2282 C - Back and Forth(模拟路径)
- Back and Forth 题解
- hdu4870 Rating 2014 Multi-University Training Contest 1
- Good Bye 2016 C. New Year and Rating(二分)
- HackerRank Hiring Contest - D Array and Queries (单调栈思想)
- 颜色直方图的计算、显示、处理、对比及反向投影(How to Use Histogram? Calculate, Show, Process, Compare and BackProject)
- 多线程JUnit单元测试:GroboUtils and ConTest
- HDU5406---CRB and Apple( DP) 2015 Multi-University Training Contest 10
- Tasks and Back Stack
- 安卓:Activity:Tasks and Back Stack