| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这样做超时了,求不超时算法。。。//系数有点像杨辉三角,DP 先谢了。。
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN=100000;
int c[MAXN+1],d[MAXN+1];
int n,m;
void dp()
{
for(int i=0;i<=n;i++)
c[i]=d[i]=0;
int *now=c,*last=d,*temp;
now[0]=last[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
now[j]=(last[j]+last[j-1])%m;
temp=last;
last=now;
now=temp;
}
int total=0;
int first;
for(int i=1;i<n;i++)
if(last[i]==0)total++,first=i;
cout<<total<<endl;
for(int i=1;i<n;i++)
if(last[i]==0)
{
cout<<i+1;
if(i==first)
cout<<endl;
else
cout<<" ";
}
}
int main()
{
while(cin>>n>>m)
dp();
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator