agrinet
krustra+并查过的..既然贪心,所以优先队列…
struct cmp{
bool operator()(int& a,int& b){
return a>b;
}
};
struct path{
int fr,to;
int dis;
bool operator<(const path &b)const{
return dis>b.dis;
}
}temp;
priority_queue<int,vector<int>,cmp>tmep;
priority_queue<path>pq;
尽管题解是这么说的…
Since the tree sizes are small enough, we don’t need any complicated data structures: we just consider every node each time.
inflate
完全背包,扫两遍就完了…注意扫的时候max
但是没想到的是
The array is always nondecreasing, so we simply output the last element of the array.
*humble
可怕..
第n个生成数 写出来最暴力算法(跪在第五个数据)后去nocow看题解
16A..
然后回来发现 官方题解居然也几乎是最暴力的
有一点概率算法的感觉 和OJ在拼空间和时间=.=
题目大概是 用set来得到第n个数(这样大概是O(n2))的感觉,但是要加一个优化,防止爆空间,加一点优化,防止溢出.(居然可以用double……).
不用set加一个数组保持每一次扫每一个质数只判一次
*contact
第一位补1的二进制hashnocow
/*边读边处理真是精彩*/
while((c = getc(fin)) != EOF) {
if(c != '0' && c != '1')
continue;
bit <<= 1;
if(c == '1')
bit |= 1;
if(nbit < b)
nbit++;
for(i=a; i<=nbit; i++)
addseq(bit, i);
}
/* increment the count for the n-bit sequence "bits" */
void
addseq(unsigned bits, int n)
{
bits &= (1<<n)-1;
bits |= 1<<n;
assert(seq[bits].bits == bits);
seq[bits].count++;
}
/* print the bit sequence, decoding the 1<<n stuff */
/* recurse to print the bits most significant bit first */
void
printbits(FILE *fout, unsigned bits)
{
assert(bits >= 1);
if(bits == 1) /* zero-bit sequence */
return;
printbits(fout, bits>>1);
fprintf(fout, "%d", bits&1);
}
*stamps
疑似多重背包 暴力做挂在第十个数据
缘由没有实践递推
的思想,太多次扫整个数组了 要么爆空间,要么会爆时间
所以关键是降低每一个数的扩展或被扩展次数
方法是对每一个到达的数扩展一位
官方题解也是每次扩展一位 只是循环的顺序不同 需要初始化为inf
也可以这样
for (i=1;i<=2000000;i++)
{
f[i]=BIGNUM;
for (j=0;j<m;j++)
if (a[j]<=i) f[i]=min(f[i],f[i-a[j]]+1);
if (f[i]>n) break;
}