結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-12 00:24:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,015 bytes |
| コンパイル時間 | 1,847 ms |
| コンパイル使用メモリ | 161,692 KB |
| 実行使用メモリ | 13,928 KB |
| 最終ジャッジ日時 | 2024-10-15 01:00:46 |
| 合計ジャッジ時間 | 3,160 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
int dp[1111111],p[1111111],b[1111111];
void Main() {
int T;
cin >> T;
while(T--) {
int x,y,n;
cin >> x >> y >> n;
if(x<y)swap(x,y);
int a[n];
rep(i,n) cin >> a[i];
sort(a,a+n);
memset(dp,-1,sizeof(dp));
memset(p,-1,sizeof(p));
dp[0]=0;
rep(i,n) {
rrep(j,x) {
if(dp[j]!=-1&&j+a[i]<=x) {
if(dp[j+a[i]]<=dp[j]+1) {
dp[j+a[i]]=dp[j]+1;
p[j+a[i]]=j;
b[j+a[i]]=i;
}
}
}
}
int M=0,now=-1;
rep(i,x+1) {
if(dp[i]>=M) {
now=i;
M=dp[i];
}
}
bool u[n];
mem(u);
while(now>-1) {
u[b[now]]=1;
now=p[now];
}
memset(dp,-1,sizeof(dp));
dp[0]=0;
rep(i,n) {
if(u[i]) continue;
rrep(j,y) {
if(dp[j]!=-1&&j+a[i]<=y) {
dp[j+a[i]]=max(dp[j+a[i]],dp[j]+1);
}
}
}
int ans=0;
rep(i,y+1) ans=max(ans,M+dp[i]);
pr(ans);
}
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
Main();return 0;
}