Topcoder SRM 565 Div.2
2012-12-22 16:47
357 查看
Pt.250:
水题,略过
pt.500:
题意:有个哥们要走过一段路,每段路上都有怪兽要打,怪兽有俩值DREAD和PRICE。每个怪兽你可以买通它,如果买通它就会跟着你走。如果你要过一个怪兽,要么买通它,要么当前跟你走的怪兽的DREAD值和大于等于这只怪兽的DREAD。求将这段路走完的最小费用。
题解:水DP,用DP[I][J]表示前I个花费J可以得到的最大DREAD和。
pt.1000:
(这题。。当时想出来了,但是发现时间不够,于是没写。。。但后来写了才知道,自己就算当时写也写不出来)
题意:定义一个序列A[1] = N,length(A) = K,且 A[i] | A[i+1],给定N,K,问有多少个数列满足要求。
题解:对N分解质因数,然后发现每个质因数可以单独考虑。比如,128 = 2 ^ 7.我下来只需要考虑在哪几个位置除2,除几个2。将得到的方法数相乘就可以了。.
水题,略过
#include<stdio.h> #include<string.h> #include<string> #include<vector> #include<iostream> using namespace std; class ValueHistogram{ public: vector <string> build(vector <int> fuck) { int n,i,j,max = 0,sum[10] = {0}; string xx; vector <string> ret; n = fuck.size(); for(i = 0;i < n;i++) { sum[fuck[i]]++; if (max < sum[fuck[i]]) max = sum[fuck[i]]; } for(i = max+1;i >= 1;i--) { xx = ".........."; for(j = 0;j < 10;j++) if (sum[j] >= i) xx[j] = 'X'; ret.push_back(xx); } return ret; } };
pt.500:
题意:有个哥们要走过一段路,每段路上都有怪兽要打,怪兽有俩值DREAD和PRICE。每个怪兽你可以买通它,如果买通它就会跟着你走。如果你要过一个怪兽,要么买通它,要么当前跟你走的怪兽的DREAD值和大于等于这只怪兽的DREAD。求将这段路走完的最小费用。
题解:水DP,用DP[I][J]表示前I个花费J可以得到的最大DREAD和。
#include<iostream> #include<string> #include<string.h> #include<vector> using namespace std; class MonstersValley2{ public: long long dp[30][50]; long long Max(long long a,long long b) { if (a > b) return a; return b; } int minimumPrice(vector <int> dread,vector <int> price){ int n,MaxP,i,j; n = dread.size(); MaxP = 2 * n; memset(dp,0,sizeof(dp)); for(i = price[0];i <= MaxP;i++) dp[0][i] = (long long)dread[0]; for(i = 1;i < n;i++) for(j = 1;j <= MaxP;j++) { if (j > price[i] && dp[i-1][j-price[i]] > 0) dp[i][j] = dp[i-1][j-price[i]] + (long long)dread[i]; if ((long long)dread[i] <= dp[i-1][j]) dp[i][j] = Max(dp[i-1][j],dp[i][j]); if (j > 1) dp[i][j] = Max(dp[i][j-1],dp[i][j]); } for(i = 0;i < n;i++) { for(j = 1;j <= MaxP;j++) cout << dp[i][j] << " "; cout << endl; } i = 1; while(dp[n-1][i] == 0) i++; return i; } };
pt.1000:
(这题。。当时想出来了,但是发现时间不够,于是没写。。。但后来写了才知道,自己就算当时写也写不出来)
题意:定义一个序列A[1] = N,length(A) = K,且 A[i] | A[i+1],给定N,K,问有多少个数列满足要求。
题解:对N分解质因数,然后发现每个质因数可以单独考虑。比如,128 = 2 ^ 7.我下来只需要考虑在哪几个位置除2,除几个2。将得到的方法数相乘就可以了。.
#include<iostream> #include<string> #include<vector> #define LL long long #define MOD 1000000009 #define MAXP 1000000 using namespace std; class DivisibleSequence{ private: bool vis[MAXP+10]; vector <int> prime; public: // LL exp_mod(LL a,LL b,LL p){// 快速幂 if(b==0) return 1; if(b==1) return a%p; LL t=exp_mod(a,b/2,p); t=t*t%p; if(b&1) t=(t*a)%p; return t; } LL cm(LL n,LL m,LL p){ //利用 逆元求 C(n,m)%p;主要利用 a/b%p=a*b'%p ,b的逆元 LL a,b,ans=1; for(LL i=1;i<=m;i++){ a=(n+i-m)%p; b=i%p; ans=ans*(a*exp_mod(b,p-2,p)%p)%p; } return ans; } LL Lucas(LL n,LL m,LL p){ if(m==0) return 1; return (Lucas(n/p,m/p,p)*cm(n%p,m%p,p))%p; } // void init() { int i,j; memset(vis,0,sizeof(vis)); for(i = 2;i <= MAXP;i++) if (vis[i] == 0) { prime.push_back(i); for(j = i << 1;j <= MAXP;j+=i) vis[j] = 1; } } int count(int a,int b) { LL ans = 1,tmp,sum; int i,j; init(); b--; int P = prime.size(); for(i = 0;i < P;i++) { tmp = 1; sum = 0; while(a % prime[i] == 0) sum++,a /= prime[i]; if (sum == 0) continue; for(j = 1;j <= sum;j++) { tmp = (tmp + Lucas(j+b-1,j,MOD)) % MOD; //cout << cal_xy(b,j) << " " << A(j) << endl; } ans = (ans * tmp) % MOD; } if (a > 1) ans = (ans * (b+1)) % MOD; return (int)ans; } };
相关文章推荐
- TopCoder SRM 633 Div.2 500 Jumping
- TopCoder SRM 639 Div.2 500 AliceGameEasy --乱搞
- Topcoder SRM 637 (Div.2)
- Topcoder SRM 721 Div.2 A. FlightDataRecorder
- Topcoder SRM 721 Div.2 B. RememberWordsEasy
- topcoder-SRM565-div2-第二题-500分--搜索/动态规划
- Topcoder SRM 721 Div.2 C. ApocalypseEasy
- Topcoder SRM 648 (div.2)
- TopCoder SRM 642 Div.2 1000 --二分+BFS
- 【topcoder第一弹】 SRM 144 Div.2 whatTime
- TopCoder SRM 634 Div.2[ABC]
- Topcoder srm 653 div.2 1000 - SingingEasy(区间DP)
- Topcoder SRM 648 Div.2 - A(水), B(枚举),C(DP/构造)
- Topcoder srm 653 div.2 500 - RockPaperScissorsMagicEasy(DP)
- TopCoder SRM 639 Div.2 500 AliceGameEasy
- Topcoder SRM 358:BalanceScale
- topcoder SRM 513 DIV2
- TopCoder——SRM 519 DIV 2
- TopCoder SRM 557 div1
- TopCoder SRM 382 CharmingTicketsEasy