1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
| #include <iostream> #include <algorithm> #include <vector> #include <string> #include <cstring> #include <stack> #include <queue> using namespace std; const int MAXN=10; struct Card{ int type; int damage; int cost; int power;
Card(){} Card(int type,int damage,int cost,int power):type(type),damage(damage),cost(cost),power(power){} } cards[MAXN]; bool used[MAXN]; int nlen; int md1,md2,md3; int mx1,mx2,mx3;
stack<int> ans_cards,ans_target; bool dfs(int stone,int power,int bl_me,int bl_en,int m1,int m2,int m3,int depth,bool nearend=false){ if(stone<0)return false; if(depth>=3)return false; if(bl_en<=0)return true;
if(depth>=1 && stone==10){ if(m1>0)bl_me-=md1; if(m2>0)bl_me-=md2; if(m3>0)bl_me-=md3;
if(m1<=0)m1=mx1; if(m2<=0)m2=mx2; if(m3<=0)m3=mx3; } if(bl_me<=0)return false;
int fullattack=0; int fakepower=power; int unusd_lian=0; for(int i=0;i<nlen;i++){ if(used[i])continue; fakepower+=cards[i].power; if(cards[i].type==1)continue; unusd_lian++; fullattack+=cards[i].damage; } if(fullattack+fakepower*(unusd_lian)<bl_en)return false;
for(int i=0;i<nlen;i++){ if(used[i])continue; const Card &card=cards[i]; int reald=card.damage+power;
if(card.cost>stone)continue;
used[i]=1; if(!nearend && card.type==1){ if(stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en,m1-reald,m2-reald,m3-reald,depth)){ ans_cards.push(i+1); ans_target.push(-1); return true; } } if(!nearend && card.type==2){ if(stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en-reald,m1,m2,m3,depth)){ ans_cards.push(i+1); ans_target.push(-1); return true; } } if(card.type==3){ if(stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en-reald,m1,m2,m3,depth,1)){ ans_cards.push(i+1); ans_target.push(0); return true; }
if(m1>0 && stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en,m1-reald,m2,m3,depth,1)){ ans_cards.push(i+1); ans_target.push(1); return true; }
if(m2>0 && stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en,m1,m2-reald,m3,depth,1)){ ans_cards.push(i+1); ans_target.push(2); return true; }
if(m3>0 && stone-card.cost>=0 && dfs(stone-card.cost,power+card.power,bl_me,bl_en,m1,m2,m3-reald,depth,1)){ ans_cards.push(i+1); ans_target.push(3); return true; } } used[i]=0; }
if(dfs(10,0,bl_me,bl_en,m1,m2,m3,depth+1)){ ans_cards.push(-1); ans_target.push(-1); return true; }
return false; } int mc1,mc2,mc3; int bl_me,bl_en; int main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int kase;cin>>kase; while(kase--){ memset(used,0,sizeof(used)); while(!ans_cards.empty())ans_cards.pop(); while(!ans_target.empty())ans_target.pop();
cin>>nlen; cin>>bl_me>>bl_en;
cin>>md1>>mc1>>mx1; cin>>md2>>mc2>>mx2; cin>>md3>>mc3>>mx3; for(int i=0;i<nlen;i++){ cards[i].cost=cards[i].damage=cards[i].power=cards[i].type=0; int type;cin>>type; if(type==1 || type==2){ int cost,x,y; cin>>cost>>x>>y; cards[i].type=type; cards[i].cost=cost; cards[i].damage=x; cards[i].power=y; }else{ int cost,x; cin>>cost>>x; cards[i].type=type; cards[i].cost=cost; cards[i].damage=x; } } ans_cards.push(-1); ans_target.push(-1); if(dfs(10,0,bl_me,bl_en,mc1,mc2,mc3,0)){ cout<<"Yes\n"; }else{ cout<<"No\n"; continue; } int block=0; while(!ans_cards.empty()){ queue<int> pack_ans,pack_target; while(!ans_cards.empty() && ans_cards.top()!=-1){ pack_ans.push(ans_cards.top()); ans_cards.pop(); pack_target.push(ans_target.top()); ans_target.pop(); }
if(!ans_cards.empty()){ ans_cards.pop(); ans_target.pop(); }
if(pack_ans.empty())continue;
cout<<pack_ans.size()<<"\n"; while(!pack_ans.empty()){ cout<<pack_ans.front()<<" "; pack_ans.pop(); } cout<<"\n"; while(!pack_target.empty()){ cout<<pack_target.front()<<" "; pack_target.pop(); } cout<<"\n"; block++; } while(block<3){ cout<<"0\n"; block++; } }
return 0; }
|