摘要: 先dfs球每个点的子树总结点数(包括他自己)。。然后就显然了。。# include # include # include # include # include using namespace std;int d[20000],pa[20000];typedef struct NODE{ int k;struct NODE* next;}Node;Node edge[2*20000],*G[10001],*tail = edge;void add(int a,int b){ tail->k = b;tail->next = G[a];G[a] = tail++;}int dfs( 阅读全文
posted @ 2013-11-09 18:43 1carus 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 经典dp。。不多说啦。因为他是n-1条边,所以不用考虑森林的情况# include # include # include # include # include # define inf -0x7ffffffusing namespace std;typedef struct NODE{ int k;struct NODE* next;}Node;Node edge[7000],*tail=edge,*G[7000];void add(int a,int b){ tail->k = b;tail->next = G[a];G[a] = tail++;}int v[7000],vi 阅读全文
posted @ 2013-11-09 15:04 1carus 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 贪心+dp# include # include # include # define inf -0x7ffffffusing namespace std;int a[2000],b[2000],d[1001][1001];int dp(int i,int j){ if (i>j) return 0; if (d[i][j]!=inf) return d[i][j]; int t = j-i+1; if (a[j]>b[t]) return d[i][j] = dp(i,j-1)+200; if (a[j]<b[t]) return d[i][j] = dp(i+... 阅读全文
posted @ 2013-11-09 12:00 1carus 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 要注意边界条件的判断(第一次写的麻烦了。。)# include # include # include # define inf 0x8fffffff;using namespace std;int max(int a,int b){ return a>b?a:b;}int dp[2][4000][2],v[4000];int main(){ int n,b,i,j,ans = 0; scanf("%d%d",&n,&b); for (i=1;i<=n;++i) scanf("%d",&v[i]); memset(dp 阅读全文
posted @ 2013-11-07 02:59 1carus 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 这题好像有点卡精度啊。。我最后用c++交,ac了# include # include # include # include # define inf 0x3fffffffusing namespace std;int map[8][8];double ave,d[20][10][10][10][10],sum[10][10];double f(int i,int j,int m,int n){ double t = sum[j+1][n+1] - sum[j+1][m] - sum[i][n+1] + sum[i][m]; return (t - ave)*(t- ave);}... 阅读全文
posted @ 2013-11-06 01:25 1carus 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 这题我做了好几天(真是弱),刚开始不会,然后苏神教了我好长时间,但是我智商太低!还是不懂。。于是我不得已去看题解。。我一直觉得tc那个神马vexorian写的题解有点反人类,所以一直不想看,结果这场不是他写的(囧)。。一看就懂了思路嘛。。大概就是一个位置可以放0,可以放1,但是放0有区间限制,怎么办呢?用一个last记录一下前一个1,如果不在以i结尾的区间内,那这个位置就必须放1了。。贴个代码#include #include #include #include #include #include #include #include #include #include #include #in 阅读全文
posted @ 2013-11-02 21:57 1carus 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 合并果子倒过来,贪心策略的正确性嘛。。大约凭借直觉想一下,因为次数要不停的往后累加,所以越小的越早合并越好,这样对后面影响小。严格证明就是huffman tree了。话说类似的贪心策略好像还有srm536的1000pt,因为那个题要求最大的合并方法,所以越小的越靠前合并对后面的影响就越小。这种题,先用stl爽一下!# include # include # include # include # include # include typedef long long ll;using namespace std;priority_queue,greater > q;int main(){ 阅读全文
posted @ 2013-10-29 21:17 1carus 阅读(162) 评论(0) 推荐(1) 编辑
摘要: 好暴力的dp啊。。有木有更简单的方法呢?# include # include # include # include # include # define MOD 1234567891using namespace std;typedef long long ll;ll dp[50][10][4][4][4][4];class TheBrickTowerHardDivTwo{public: int find(int C, int K, int H) { ll n,k,a,b,c,d,x,y,z,i,ans=0ll; for (a=0;a<C;++a) ... 阅读全文
posted @ 2013-10-29 19:58 1carus 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 要注意锤子可以移到负坐标(解决:把正方形边长增加d)。一条直线上的格点数是GCD+1 阅读全文
posted @ 2013-10-22 17:47 1carus 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 做了好长时间,害的苏神又跟我强调了一遍做dp的技巧。。。首先当然要枚举stamp的长度len了,然后设dp[j]['C']表示这个位置涂成c颜色最少需要几次,假如用c[k]染第j个格子,看j的前len-1个位置合不合法,合法就是颜色和第j格相同或者是‘*’啦,如果不合法,就跳出,如果合法,就更新dp[j]['C'] = min{dp[j]['C'],dp[k]['C']+1 (j-len# include # include # include # include # define maxi 0xfffffffusing name 阅读全文
posted @ 2013-10-15 21:31 1carus 阅读(211) 评论(0) 推荐(0) 编辑