rating又掉了。。。变灰色了%>_<%。250pt很简单,一眼看上去是个背包,没有多想立马写了个01背包,后面发现其实就是个简单的排序。。。因为只是需要求数量而已。500pt被我写残了,fst了,有一组极限数据超时了,我脑残的用了O(n)时间复杂度的质因数分解 10^9必定超时啊。。。。还是没想清楚就写了,真的得记住:想得多写得少,并且正确率也会提高很多。950pt思路是有了,没有时间写了,当时想用Trie统计下每个单词路径上经过了有多少个单词,然后再进行相应的计算,其实没必要用Trie,因为数据规模很小(n<=50),直接暴力搞一下就好了。

1. 250pt MiniatureDachshund

题意

有一些香肠,每个香肠都有一个重量,Lun的小狗很喜欢吃香肠,如果狗狗吃了某个香肠,那么它的体重的增加量等于香肠的重量,狗狗希望吃到尽量多得香肠,但体重又不超过5000克(会给出小狗的体重),问狗狗最多能吃到多少根香肠?

题解

把香肠重量从小到大排下序,然后依次累加直到超过5000,也可以用背包,就是用5000减去小狗的体重作为容量,然后就是在背包中放入尽量多的香肠

代码:

背包搞的。。。

class MiniatureDachshund
{
public:
int maxMikan(vector <int> mikan, int weight)
{
int dp[];
memset(dp,,sizeof(dp));
int v=-weight;
for(size_t i=; i<mikan.size(); i++)
for(int j=v; j>=mikan[i]; j--)
dp[j]=max(dp[j],dp[j-mikan[i]]+);
return dp[v];
}
};

2. 500pt BigFatInteger2

题意

给定四个整数A,B,C,D(1<=A,B,C,D<=10^9),判断AB%CD=0

题解

得把A和C进行质因数分解,分解成这样的形式 :p1a1*p2a2*p3a3…pnan ,对于每一个p,假设A和C指数分别为b,d,那么如果出现b*B<d*D那么AB%CD!=0,否则就是可以整除

代码:很挫…

map<int,int>a,b;
int prime[MAXN],cnt=;
bool check[MAXN];
void go(int x)
{
if(x==)
{
a[]++;
return;
}
for(int i=; i<cnt&&x>; i++)
if(x%prime[i]==)
{
while(x%prime[i]==)
{
a[prime[i]]++;
x/=prime[i];
}
}
if(x>) a[x]++;
}
bool checks(int B,int x,int D)
{
if(x==) return true;
for(int i=; i<cnt&&x>; i++)
if(x%prime[i]==)
{
while(x%prime[i]==)
{
b[prime[i]]++;
if((LL)b[prime[i]]*(LL)D>(LL)a[prime[i]]*(LL)B) return false;
x/=prime[i];
}
}
if(x>) b[x]++;
if((LL)b[x]*(LL)D>(LL)a[x]*(LL)B) return false;
return true;
}
void get_prime()
{
int high=MAXN;
memset(check,false,true);
cnt=;
for(int i=; i<=high; i++)
{
if(!check[i])
prime[cnt++]=i;
for(int j=; j<cnt&&i*prime[j]<=high; j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==) break;
}
}
}
class BigFatInteger2
{
public:
string isDivisible(int A, int B, int C, int D)
{
a.clear();
b.clear();
get_prime();
go(A);
if(!checks(B,C,D))
return "not divisible";
return "divisible";
}
};

3. 950pt SimilarNames2

题意

给定n个单词和整数L,要求你对n个单词进行排列,使得每个在[0,L-2]的单词i刚好是单词i+1的前缀,问总共有多少种排列方法?

题解

先对单词进行排序,然后暴力求出每个单词中的前缀恰好也是单词的前缀数量cnt,那么答案就是ans=sigma(C(cnt[i]-1,L-1)*(n-L)!)(0<=i<=n)(C(n,m)表示组合数)

代码:

#define MOD 1000000007
typedef long long LL;
LL dp[][],cnt[];
class SimilarNames2
{
public:
bool check(string a,string b)
{
if(a.size()<=b.size()&&b.substr(,a.size())==a) return true;
return false;
}
void Comb()
{
for(int i=; i<=; i++)
{
dp[i][]=,dp[i][i]=;
for(int j=; j<i; j++)
dp[i][j]=(dp[i-][j]+dp[i-][j-])%MOD;
}
}
int count(vector <string> names, int L)
{
sort(names.begin(),names.end());
int len=names.size();
memset(dp,,sizeof(dp));
for(int i=; i<len; i++)
{
cnt[i]=;
for(int j=; j<i; j++)
{
if(check(names[j],names[i]))
cnt[i]=max(cnt[i],cnt[j]+);
}
}
Comb();
LL fac=;
for(LL i=; i<=len-L; i++)
fac=(fac*i)%MOD;
int ans=;
for(int i=; i<len; i++)
if(cnt[i]>=L)
ans=((LL)ans+dp[cnt[i]-][L-]*fac)%MOD;
return ans;
}
};

SRM 599 DIV 2的更多相关文章

  1. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

  2. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  3. 竞赛图的得分序列 (SRM 717 div 1 250)

    SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, ...

  4. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  5. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

  6. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  7. SRM 638 Div.2

    250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamel ...

  8. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  9. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

随机推荐

  1. Samza文档翻译 : Architecture

    http://samza.incubator.apache.org/learn/documentation/0.7.0/introduction/architecture.html Samza由三层组 ...

  2. 论MOBA类游戏五号位的重要性

    观众朋友们,也许你对题目很好奇,才打开这篇文章.为什么技术圈中会出现游戏类的软文?如果时间充足,可以继续往下看. MOBA 类游戏的兴起,逐渐吞噬游戏市场,以病毒式的扩张方式肆意改变着游戏玩家内心对游 ...

  3. HDU1465+递推

    经典的信封装信问题 f[ n ]  = ( n-1 ) * ( f[ n-1 ]+f[ n-2 ] ) #include<stdio.h> #include<string.h> ...

  4. CodeForces152C——Pocket Book(排列组合问题)

    Pocket Book DescriptionOne day little Vasya found mom's pocket book. The book had n names of her fri ...

  5. P127、面试题20:顺时针打印矩阵

    题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字.例如:如果输入如下矩阵:1  2  3  4 5  6  7  89  10  11  1213  14  15  16则依次打印出 ...

  6. laravel Authentication and Security

    Creating the user modelFirst of all, we need to define the model that is going to be used to represe ...

  7. netty 实现socket服务端编写

    import java.net.InetSocketAddress; import io.netty.bootstrap.ServerBootstrap; import io.netty.channe ...

  8. String Split 和 Join

    很多时候处理字符串数据,比如从文件中读取或者存入 - 我们可能需要加入分隔符(如CSV文件中的逗号),或使用一个分隔符来合并字符串序列. 很多人都知道使用split()的方法,但使用与其对应的Join ...

  9. pylinter could not automatically determined the path to `lint.py`

    先关闭Sublime Text 1) 到官网先下载pylinter,http://www.logilab.org/project/pylint,然后解压缩,拷贝到C盘,目录为C:\pylint-1.0 ...

  10. HDU 5280 Senior's Array (暴力,水)

    题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. #include < ...