题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2527
//ps:算法跟hdu 1053类似
#include
#include
#include
#include
using namespace std;
struct node
{
int key;
int f;
int lson,rson;
bool operator < (const node x)const
{
return x.key<key;
}
};
node father;
node g[3100];
int sum=0;
void fuc(node x,int cnt);
int main()
{
int n,temp;
cin>>n;
while(n--)
{
char str[1100];
cin>>temp;
scanf("%s",str);
sum=0;
priority_queue p;
int len=strlen(str);
int ii=0;
for(int i=0;i
{
int cnt=1;
char c;
if(str[i]!='#')
{
c=str[i];
str[i]='#';
for(int j=i+1;j
{
if(str[j]==c)
{
cnt++;
str[j]='#';
}
}
g[ii].f=ii;
g[ii].lson=g[ii].rson=-1;
g[ii].key=cnt;
p.push(g[ii]);
ii++;
}
}
if(ii==1)
{
if(len<=temp)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
else
{
while(p.size()!=1)
{
node tmp1,tmp2;
tmp1=p.top();
p.pop();
tmp2=p.top();
p.pop();
g[ii].f=ii;
g[ii].lson=tmp1.f;
g[ii].rson=tmp2.f;
tmp1.f=ii;
tmp2.f=ii;
g[ii].key=tmp1.key+tmp2.key;
p.push(g[ii]);
ii++;
}
father=p.top();
p.pop();
fuc(father,0);
if(sum<=temp)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}
return 0;
}
void fuc(node x,int cnt)
{
if(x.lson==-1&&x.rson==-1)
{
sum+=x.key*cnt;
return ;
}
fuc(g[x.lson],cnt+1);
fuc(g[x.rson],cnt+1);
}
//ps:算法跟hdu 1053类似
#include
#include
#include
#include
using namespace std;
struct node
{
};
node father;
node g[3100];
int sum=0;
void fuc(node x,int cnt);
int main()
{
}
void fuc(node x,int cnt)
{
}