# ***[Tioj 冰塊塔](https://tioj.ck.tp.edu.tw/problems/1993)*** ###### tags: `algorithm` `bitset` `c++` `bitwise Operator` ```cpp=1 #include<bits/stdc++.h> using namespace std; const int maxn=1e5+5; bitset<maxn>d; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t,n,h,a,b,c; cin>>t; while(t--) { cin>>n>>h; if(n==0) cout<<0<<endl; //有沒有這行沒差XD d.reset(); d[0]=1; int i; for(i=1;i<=n;++i) { cin>>a>>b>>c; d=d<<a|d<<b|d<<c; } for(i=h;i>0&&d[i]!=1;i--); if(i==0) cout<<"no solution"<<endl; else cout<<i<<endl; } } ``` ## Code Explaination **<font color="#f00">11</font> t: 測資組數** **<font color="#f00">12</font> n: 冰塊數量 h: 天花板高度** **<font color="#f00">14</font> bitset歸0** **<font color="#f00">15</font> 設最右邊位為1** **<font color="#f00">16</font> 當輸入長寬高 bitset儲存這個3個高度都有可能,可能者設為1 之後不斷更新 EX: i=0 d=...000000000000000000000 i=1 a=3 b=5 c=9 d=(第maxn位)...0001000101000(第0位) i=2 a=4 b=2 c=1 d=(第maxn位)..10111011111000(第0位)** **<font color="#f00">21</font> 從i=h往下找被設為1的最大高度**
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up