水题,思路很清晰
#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int N=121;
typedef long long LL;
int xh[105];
int main()
{
int i,t,n,m,a;
cin>>t;
while(t--)
{
memset(xh,0,sizeof(xh));
cin>>n;
m=n;
int max=0;//max记录最高层
while(m--)
{
scanf("%d",&a);
if(max<a) max=a;
xh[a]++;//a层人数+1
}
int temp=0,sum=0;//temp记录上一次电梯停的层数,sum总共需要多长时间
for(i=0;i<=max;i++)
{
while(xh[i]==0) i++;
sum+=xh[i]+(i-temp)*6+5;//下的人时间+上升的时间+开门5秒
temp=i;
}
sum+=max*4;//下降的时间
cout<<sum<<endl;
}
return 0;
}
可以看出来,新的值是在原来某一个值*k^t
用快速幂就ok了
#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int N=10021;
const int mod=1000000007;
typedef __int64 LL;
LL n,xh[N],k,t;
LL powkt()
{
LL a=k,b=t,x=1;
while(b)
{
if(b%2==1)
x=(x*a)%mod;
b/=2;
a=(a*a)%mod;
}
return (x)%mod;
}
int main()
{
int i,T,j;
cin>>T;
while(T--)
{
scanf("%I64d%I64d%I64d",&n,&t,&k);
for(i=1;i<=n;i++)
scanf("%I64d",&xh[i]);
LL kt=powkt();//求k^t
int s=0;
t%=n;
if(t==0)
s=1;
else
s=n-t+1;
for(i=1;i<=n;i++)
{
if(i!=1)
printf(" ");
printf("%I64d",(kt*xh[s])%mod);
s++;
if(s>n)
s=1;
}
printf("\n");
}
return 0;
}
完全背包,好久都没敲dp了,手都生了。
#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int N=121;
typedef long long LL;
int w[N],v[N],dp[100010];//这个地方dp别写成N了
int n,maxv;
int main()
{
int i,j;
while(cin>>n)
{
for(i=1;i<=n;i++)
scanf("%d%d",&w[i],&v[i]);
scanf("%d",&maxv);
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
for(j=v[i];j<=maxv;j++)
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
printf("%d\n",dp[maxv]);
}
return 0;
}